mutateAndCheck

original_code:
unsigned int mutateAndCheck(password *newdict, password *olddict, unsigned int numwords){
    printf("Starting with dictionary manipulation.\n");
    unsigned int i, found=0;
    int z;
    word16 md5Hash;
    for (z=-1;z<252 && !found;z++){
        memcpy(newdict,olddict,numwords*sizeof(password));
        if(z != -1){
            for (i=0;i<numwords;i++){
               if (z==0){
                    if (newdict[i].word[0] >= 'a' && newdict[i].word[0] <= 'z')
                        newdict[i].word[0] +='A'-'a';
               }
               if (z==1){
                    size_t len = newdict[i].length;
                    if (newdict[i].word[len-1] >= 'a' && newdict[i].word[len-1] <= 'z')
                        newdict[i].word[len-1] += 'A'-'a';
               }
               if (z>=2 && z<=11){
                    size_t len = newdict[i].length;
                    newdict[i].word[len] = '0' + z-2;
                    newdict[i].length += 1;
               }
               if (z>=12 && z<=111){
                    size_t len = newdict[i].length;
                    newdict[i].word[len] = '0' + ((z-12)/10)%10;
                    newdict[i].word[len+1] = '0' + (z-12)%10;
                    newdict[i].length += 2;
               }
               if (z>=112 && z<=231){
                    size_t len = newdict[i].length;
                    newdict[i].word[len] = '0' + ((z+1900-112)/1000)%10;
                    newdict[i].word[len+1] = '0' + ((z+1900-112)/100)%10;
                    newdict[i].word[len+2] = '0' + ((z+1900-112)/10)%10;
                    newdict[i].word[len+3] = '0' + (z+1900-112)%10;
                    newdict[i].length += 4;
               }
                if (z>=232 && z<=251){
                    size_t len = newdict[i].length;
                    memcpy(&(newdict[i].word[len]),seq[z-232].word,seq[z-232].length);
                    newdict[i].length = len + seq[z-232].length;
                }
            }
        }
        found = getMD5(newdict, &md5Hash, numwords);
    }
    return found;
}

canonical_original_code:
unsigned int mutateAndCheck(struct password_t *newdict, struct password_t *olddict, unsigned int numwords){
    printf("Starting with dictionary manipulation.\n");
    unsigned int i; unsigned int found = 0;
    int z;
    struct word16_t md5Hash;
    for (z=-1;z<252 && !found;z++){
        memcpy(newdict,olddict,numwords*sizeof(password));
        if(z != -1){
            for (i=0;i<numwords;i++){
               if (z==0){
                    if (newdict[i].word[0] >= 'a' && newdict[i].word[0] <= 'z')
                        newdict[i].word[0] +='A'-'a';
               }
               if (z==1){
                    unsigned long len = newdict[i].length;
                    if (newdict[i].word[len-1] >= 'a' && newdict[i].word[len-1] <= 'z')
                        newdict[i].word[len-1] += 'A'-'a';
               }
               if (z>=2 && z<=11){
                    unsigned long len = newdict[i].length;
                    newdict[i].word[len] = '0' + z-2;
                    newdict[i].length += 1;
               }
               if (z>=12 && z<=111){
                    unsigned long len = newdict[i].length;
                    newdict[i].word[len] = '0' + ((z-12)/10)%10;
                    newdict[i].word[len+1] = '0' + (z-12)%10;
                    newdict[i].length += 2;
               }
               if (z>=112 && z<=231){
                    unsigned long len = newdict[i].length;
                    newdict[i].word[len] = '0' + ((z+1900-112)/1000)%10;
                    newdict[i].word[len+1] = '0' + ((z+1900-112)/100)%10;
                    newdict[i].word[len+2] = '0' + ((z+1900-112)/10)%10;
                    newdict[i].word[len+3] = '0' + (z+1900-112)%10;
                    newdict[i].length += 4;
               }
                if (z>=232 && z<=251){
                    unsigned long len = newdict[i].length;
                    memcpy(&(newdict[i].word[len]),seq[z-232].word,seq[z-232].length);
                    newdict[i].length = len + seq[z-232].length;
                }
            }
        }
        found = getMD5(newdict, &md5Hash, numwords);
    }
    return found;
}

variable_types:
olddict
struct password_t *

variable_types:
numwords
unsigned int

variable_types:
found
unsigned int

variable_types: z int

variable_types:
len
unsigned long


startTime

repo: uttaresh/GPUHashRecoverer

decompiled_code:
int __fastcall startTime(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

original_code:
void startTime(Timer* timer) {
    gettimeofday(&(timer->startTime), ((void *)0));
}

canonical_original_code:
void startTime(struct Timer *timer) {
    gettimeofday(&(timer->startTime), ((void *)0));
}

variable_types: struct Timer { struct timeval { long tv_sec; long tv_usec; } startTime; struct timeval endTime; } *

return_type: void

user_defined_types: struct Timer { struct timeval startTime; struct timeval endTime; }


stopTime

decompiled_code:
int __fastcall stopTime(struct timeval *a1)
{
return gettimeofday(a1 + 1, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(struct timeval *a1)
{
return gettimeofday(a1 + 1, 0LL);
}

original_code:
void stopTime(Timer* timer) {
    gettimeofday(&(timer->endTime), ((void *)0));
}

canonical_original_code:
void stopTime(struct Timer *timer) {
    gettimeofday(&(timer->endTime), ((void *)0));
}

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


elapsedTime

original_code:
float elapsedTime(Timer timer) {
    return ((float) ((timer.endTime.tv_sec - timer.startTime.tv_sec) + (timer.endTime.tv_usec - timer.startTime.tv_usec)/1.0e6));
}

canonical_original_code:
float elapsedTime(struct Timer timer) {
    return ((float) ((timer.endTime.tv_sec - timer.startTime.tv_sec) + (timer.endTime.tv_usec - timer.startTime.tv_usec)/1.0e6));
}

variable_types: struct Timer { struct timeval { long tv_sec; long tv_usec; } startTime; struct timeval endTime; }

return_type: float


canonical_original_code:
void md5(struct password_t *pwd, unsigned char *digest) {
    unsigned int h0; unsigned int h1; unsigned int h2; unsigned int h3;
    unsigned int w[16];
    unsigned int a; unsigned int b; unsigned int c; unsigned int d; unsigned int i; unsigned int f; unsigned int g; unsigned int temp;
    unsigned long initial_len = pwd->length;
    unsigned char *msg = (uint8_t*)pwd->word;
    msg[initial_len] = 0x80;
    for (i = 0; i < 14; i++)
        w[i] = to_int32(msg + i*4);
    unsigned char res[4];
    to_bytes(initial_len*8, res);
    w[14] = to_int32(res);
    to_bytes(initial_len>>29, res);
    w[15] = to_int32(res);
    h0 = 0x67452301;
    h1 = 0xefcdab89;
    h2 = 0x98badcfe;
    h3 = 0x10325476;
    a = h0;
    b = h1;
    c = h2;
    d = h3;
    for(i = 0; i<64; i++) {
        if (i < 16) {
            f = (b & c) | ((~b) & d);
            g = i;
        } else if (i < 32) {
            f = (d & b) | ((~d) & c);
            g = (5*i + 1) % 16;
        } else if (i < 48) {
            f = b ^ c ^ d;
            g = (3*i + 5) % 16;
        } else {
            f = c ^ (b | (~d));
            g = (7*i) % 16;
        }
        temp = d;
        d = c;
        c = b;
        b = b + ((((a + f + k[i] + w[g])) << (r[i])) | (((a + f + k[i] + w[g])) >> (32 - (r[i]))));
        a = temp;
    }
    h0 += a;
    h1 += b;
    h2 += c;
    h3 += d;
    to_bytes(h0, digest);
    to_bytes(h1, digest + 4);
    to_bytes(h2, digest + 8);
    to_bytes(h3, digest + 12);
}

variable_types: struct password_t { char word[56]; unsigned long length; } *

variable_types:
digest
unsigned char *

variable_types:
w
unsigned int [16]

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
c
unsigned int

variable_types:
d
unsigned int

variable_types:
i
unsigned int

variable_types:
f
unsigned int

variable_types:
g
unsigned int

variable_types:
temp
unsigned int

variable_types:
msg
unsigned char *

variable_types:
res
unsigned char [4]


decompiled_code:
__int64 brute_force()
{
unsigned __int64 v0; // r13
__int64 v1; // rbx
char v2; // dl
unsigned __int64 i; // r14
unsigned int v4; // esi
unsigned __int64 v5; // rcx
__int64 result; // rax
bool v8; // cl
unsigned int v9; // [rsp+Ch] [rbp-8Ch]
char v10[16]; // [rsp+10h] [rbp-88h] BYREF
__int128 v11[3]; // [rsp+20h] [rbp-78h] BYREF
__int64 v12; // [rsp+50h] [rbp-48h]
__int64 v13; // [rsp+58h] [rbp-40h]

v0 = 1LL;
v1 = 1LL;
puts("\nStarting with brute force.");
do
{
v9 = v1;
printf("Calculating with a maximum length of %d\n", (unsigned int)v1);
v0 *= 26LL;
printf("Total number of words: %lu\n\n", v0);
if ( v0 )
{
v2 = 97;
for ( i = 0LL; ; v2 = byte_19D[i % 0x1A] )
{
v13 = v1;
v4 = v1 - 1;
v5 = i;
v12 = 0LL;
v11[0] = 0LL;
v11[1] = 0LL;
v11[2] = 0LL;
while ( 1 )
{
*((_BYTE *)v11 + v4) = v2;
v5 /= 0x1AuLL;
if ( v4-- == 0 )
break;
v2 = byte_19D[v5 % 0x1A];
}
++i;
result = getMD5(v11, v10, 1LL, v5);
v8 = (_DWORD)result == 0;
if ( v0 <= i || (_DWORD)result )
break;
}
}
else
{
v8 = 1;
result = 0LL;
}
++v1;
}
while ( v9 <= 7 && v8 );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int64 v0; // r13
__int64 v1; // rbx
char v2; // dl
unsigned __int64 i; // r14
unsigned int v4; // esi
unsigned __int64 v5; // rcx
__int64 result; // rax
bool v8; // cl
unsigned int v9; // [rsp+Ch] [rbp-8Ch]
char v10[16]; // [rsp+10h] [rbp-88h] BYREF
__int128 v11[3]; // [rsp+20h] [rbp-78h] BYREF
__int64 v12; // [rsp+50h] [rbp-48h]
__int64 v13; // [rsp+58h] [rbp-40h]

v0 = 1LL;
v1 = 1LL;
puts("\nStarting with brute force.");
do
{
v9 = v1;
printf("Calculating with a maximum length of %d\n", (unsigned int)v1);
v0 *= 26LL;
printf("Total number of words: %lu\n\n", v0);
if ( v0 )
{
v2 = 97;
for ( i = 0LL; ; v2 = byte_19D[i % 0x1A] )
{
v13 = v1;
v4 = v1 - 1;
v5 = i;
v12 = 0LL;
v11[0] = 0LL;
v11[1] = 0LL;
v11[2] = 0LL;
while ( 1 )
{
*((_BYTE *)v11 + v4) = v2;
v5 /= 0x1AuLL;
if ( v4-- == 0 )
break;
v2 = byte_19D[v5 % 0x1A];
}
++i;
result = getMD5(v11, v10, 1LL, v5);
v8 = (_DWORD)result == 0;
if ( v0 <= i || (_DWORD)result )
break;
}
}
else
{
v8 = 1;
result = 0LL;
}
++v1;
}
while ( v9 <= 7 && v8 );
return result;
}

original_code:
unsigned int brute_force(){
    printf("\nStarting with brute force.\n");
    unsigned int i = 0,found=0, j=0;
    word16 md5Hash;
    password pwd;
    char *characters = "abcdefghijklmnopqrstuvwxyz";
    uint64_t total_words = 1;
 while(i < 8 && !found){
        total_words *= 26;
        printf("Calculating with a maximum length of %d\n", i+1);
  printf("Total number of words: %lu\n\n", total_words);
  uint64_t curr_word = 0;
  uint64_t k;
  for(k=0; k<total_words && !found; k++) {
   curr_word = k;
   memset(&pwd,0,sizeof(password));
   pwd.length = i+1;
   for(j=0; j<i+1; j++) {
    pwd.word[i-j] = characters[(curr_word % 26)];
    curr_word /= 26;
   }
            found = getMD5(&pwd, &md5Hash, 1);
  }
  ++i;
 }
 return found;
}

canonical_original_code:
unsigned int brute_force(){
    printf("\nStarting with brute force.\n");
    unsigned int i = 0; unsigned int found = 0; unsigned int j = 0;
    struct word16_t md5Hash;
    struct password_t pwd;
    char *characters = "abcdefghijklmnopqrstuvwxyz";
    unsigned long total_words = 1;
 while(i < 8 && !found){
        total_words *= 26;
        printf("Calculating with a maximum length of %d\n", i+1);
  printf("Total number of words: %lu\n\n", total_words);
  unsigned long curr_word = 0;
  unsigned long k;
  for(k=0; k<total_words && !found; k++) {
   curr_word = k;
   memset(&pwd,0,sizeof(password));
   pwd.length = i+1;
   for(j=0; j<i+1; j++) {
    pwd.word[i-j] = characters[(curr_word % 26)];
    curr_word /= 26;
   }
            found = getMD5(&pwd, &md5Hash, 1);
  }
  ++i;
 }
 return found;
}

variable_types:
found
unsigned int

variable_types:
j
unsigned int

variable_types: struct password_t { char word[56]; unsigned long length; }

variable_types:
characters
char *

variable_types:
k
unsigned long

return_type: unsigned int


makeNull

repo: vacuus/archfeed

decompiled_code:
void *__fastcall makeNull(void *a1, int a2)
{
void *result; // rax

if ( a2 > 0 )
result = memset(a1, 0, a2);
return result;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1, int a2)
{
void *result; // rax

if ( a2 > 0 )
result = memset(a1, 0, a2);
return result;
}

original_code:
static void makeNull (char *s, int len) {
  int i;
  for (i = 0; i < len; i++) {
    s[i] = '\0';
  }
}

canonical_original_code:
static void makeNull(char *s, int len) {
  int i;
  for (i = 0; i < len; i++) {
    s[i] = '\0';
  }
}

variable_types:
s
char *

variable_types: len int

variable_types: i int


printHTML

decompiled_code:
void __fastcall printHTML(void *src)
{
int v1; // ebx
signed __int64 v2; // rax
void *v3; // rsp
int v4; // er13
size_t v5; // r13
__int64 v6; // r15
char v7; // r14
char *v8; // rbx
char *v9; // rax
int v10; // edx
char *v11; // r15
const unsigned __int16 *v12; // r13
size_t v13; // rax
char *v14; // rax
char *v15; // r14
__int64 v16; // [rsp+0h] [rbp-90h] BYREF
char *v17; // [rsp+8h] [rbp-88h]
char *v18; // [rsp+10h] [rbp-80h]
char *v19; // [rsp+18h] [rbp-78h]
char *s; // [rsp+20h] [rbp-70h]
char *haystack; // [rsp+28h] [rbp-68h]
int v22; // [rsp+30h] [rbp-60h] BYREF
int v23; // [rsp+34h] [rbp-5Ch] BYREF
char v24[2]; // [rsp+38h] [rbp-58h] BYREF
unsigned __int16 v25; // [rsp+3Ah] [rbp-56h]
char srca[16]; // [rsp+40h] [rbp-50h] BYREF
__int64 v27; // [rsp+50h] [rbp-40h]
int v28; // [rsp+58h] [rbp-38h]
__int16 v29; // [rsp+5Ch] [rbp-34h]

v1 = 0;
v2 = strlen((const char *)src);
v3 = alloca(v2);
v18 = (char *)&v16;
memcpy(&v16, src, v2 + 1);
ioctl(1, 0x5413uLL, v24);
v23 = 0;
v4 = ++v25;
v22 = v25;
s = (char *)malloc(v25);
makeNull(s, v4);
v27 = 0LL;
v28 = 0;
v29 = 0;
*(_OWORD *)srca = 0LL;
v5 = strlen((const char *)src);
LABEL_2:
while ( 1 )
{
v6 = v1;
if ( v1 >= v5 )
break;
while ( 1 )
{
v7 = *((_BYTE *)src + v6);
if ( v7 == 60 )
{
v9 = strtok(&v18[v6], "<>");
v10 = (unsigned __int8)*v9;
haystack = v9;
if ( v10 == 47 && v9[1] == 112 && !v9[2] )
{
v11 = s;
puts(s);
v23 = 0;
makeNull(v11, v22);
}
else
{
if ( !strcmp(haystack, "code") )
{
if ( *(_DWORD *)&flags )
{
if ( *((_DWORD *)&flags + 6) )
wrapper_constprop_0(s, "\x1B[32m", &v22, &v23);
else
printf("%s", "\x1B[32m");
goto LABEL_18;
}
}
else if ( !strcmp(haystack, "/code") && *(_DWORD *)&flags )
{
if ( *((_DWORD *)&flags + 6) )
wrapper_constprop_0(s, "\x1B[0m", &v22, &v23);
else
printf("%s", "\x1B[0m");
goto LABEL_18;
}
if ( v10 == 108 && haystack[1] == 105 && !haystack[2] )
{
putchar(9);
}
else
{
if ( !strstr(haystack, "/a") || !v17 )
{
v14 = strstr(haystack, "http");
v17 = v14;
if ( v14 )
v14[strlen(v14) - 1] = 0;
goto LABEL_18;
}
if ( *((_DWORD *)&flags + 6) )
{
if ( *(_DWORD *)&flags )
{
v15 = s;
wrapper_constprop_0(s, "\x1B[36m", &v22, &v23);
wrapper_constprop_0(v15, " <", &v22, &v23);
wrapper_constprop_0(v15, v17, &v22, &v23);
wrapper_constprop_0(v15, ">", &v22, &v23);
wrapper_constprop_0(v15, "\x1B[0m", &v22, &v23);
goto LABEL_18;
}
}
else if ( *(_DWORD *)&flags )
{
printf(" %s<%s>%s", "\x1B[36m", v17, "\x1B[0m");
goto LABEL_18;
}
printf(" <%s> ", v17);
}
}
LABEL_18:
v1 += strlen(haystack) + 2;
v5 = strlen((const char *)src);
goto LABEL_2;
}
if ( v7 == 38 )
break;
if ( v7 == 62 )
{
++v1;
goto LABEL_2;
}
if ( *((_DWORD *)&flags + 6) )
{
v12 = *_ctype_b_loc();
while ( 1 )
{
v1 = v6++;
if ( (v12[v7] & 0x2004) != 0 )
break;
srca[strlen(srca)] = v7;
v13 = strlen(srca);
v7 = *((_BYTE *)src + v6);
srca[v13 + 1] = 0;
}
if ( v7 != 60 )
{
++v1;
srca[strlen(srca)] = v7;
}
wrapper_constprop_0(s, srca, &v22, &v23);
makeNull(srca, 30);
v5 = strlen((const char *)src);
goto LABEL_2;
}
v19 = (char *)src + v6;
++v1;
putchar(v7);
if ( *v19 == 10 )
{
v23 = 0;
makeNull(s, v22);
}
v6 = v1;
v5 = strlen((const char *)src);
if ( v1 >= v5 )
goto LABEL_10;
}
v19 = (char *)src + v6;
if ( strstr((const char *)src + v6, ">") )
{
putchar(62);
v5 = strlen((const char *)src);
}
else if ( strstr(v19, "<") )
{
putchar(60);
v5 = strlen((const char *)src);
}
v1 += strlen(haystack);
}
LABEL_10:
v8 = s;
puts(s);
free(v8);
}

canonical_decompiled_code:
void __fastcall func2(void *src)
{
int v1; // ebx
signed __int64 v2; // rax
void *v3; // rsp
int v4; // er13
size_t v5; // r13
__int64 v6; // r15
char v7; // r14
char *v8; // rbx
char *v9; // rax
int v10; // edx
char *v11; // r15
const unsigned __int16 *v12; // r13
size_t v13; // rax
char *v14; // rax
char *v15; // r14
__int64 v16; // [rsp+0h] [rbp-90h] BYREF
char *v17; // [rsp+8h] [rbp-88h]
char *v18; // [rsp+10h] [rbp-80h]
char *v19; // [rsp+18h] [rbp-78h]
char *s; // [rsp+20h] [rbp-70h]
char *haystack; // [rsp+28h] [rbp-68h]
int v22; // [rsp+30h] [rbp-60h] BYREF
int v23; // [rsp+34h] [rbp-5Ch] BYREF
char v24[2]; // [rsp+38h] [rbp-58h] BYREF
unsigned __int16 v25; // [rsp+3Ah] [rbp-56h]
char srca[16]; // [rsp+40h] [rbp-50h] BYREF
__int64 v27; // [rsp+50h] [rbp-40h]
int v28; // [rsp+58h] [rbp-38h]
__int16 v29; // [rsp+5Ch] [rbp-34h]

v1 = 0;
v2 = strlen((const char *)src);
v3 = alloca(v2);
v18 = (char *)&v16;
memcpy(&v16, src, v2 + 1);
ioctl(1, 0x5413uLL, v24);
v23 = 0;
v4 = ++v25;
v22 = v25;
s = (char *)malloc(v25);
func0(s, v4);
v27 = 0LL;
v28 = 0;
v29 = 0;
*(_OWORD *)srca = 0LL;
v5 = strlen((const char *)src);
LABEL_2:
while ( 1 )
{
v6 = v1;
if ( v1 >= v5 )
break;
while ( 1 )
{
v7 = *((_BYTE *)src + v6);
if ( v7 == 60 )
{
v9 = strtok(&v18[v6], "<>");
v10 = (unsigned __int8)*v9;
haystack = v9;
if ( v10 == 47 && v9[1] == 112 && !v9[2] )
{
v11 = s;
puts(s);
v23 = 0;
func0(v11, v22);
}
else
{
if ( !strcmp(haystack, "code") )
{
if ( *(_DWORD *)&flags )
{
if ( *((_DWORD *)&flags + 6) )
func1(s, "\x1B[32m", &v22, &v23);
else
printf("%s", "\x1B[32m");
goto LABEL_18;
}
}
else if ( !strcmp(haystack, "/code") && *(_DWORD *)&flags )
{
if ( *((_DWORD *)&flags + 6) )
func1(s, "\x1B[0m", &v22, &v23);
else
printf("%s", "\x1B[0m");
goto LABEL_18;
}
if ( v10 == 108 && haystack[1] == 105 && !haystack[2] )
{
putchar(9);
}
else
{
if ( !strstr(haystack, "/a") || !v17 )
{
v14 = strstr(haystack, "http");
v17 = v14;
if ( v14 )
v14[strlen(v14) - 1] = 0;
goto LABEL_18;
}
if ( *((_DWORD *)&flags + 6) )
{
if ( *(_DWORD *)&flags )
{
v15 = s;
func1(s, "\x1B[36m", &v22, &v23);
func1(v15, " <", &v22, &v23);
func1(v15, v17, &v22, &v23);
func1(v15, ">", &v22, &v23);
func1(v15, "\x1B[0m", &v22, &v23);
goto LABEL_18;
}
}
else if ( *(_DWORD *)&flags )
{
printf(" %s<%s>%s", "\x1B[36m", v17, "\x1B[0m");
goto LABEL_18;
}
printf(" <%s> ", v17);
}
}
LABEL_18:
v1 += strlen(haystack) + 2;
v5 = strlen((const char *)src);
goto LABEL_2;
}
if ( v7 == 38 )
break;
if ( v7 == 62 )
{
++v1;
goto LABEL_2;
}
if ( *((_DWORD *)&flags + 6) )
{
v12 = *_ctype_b_loc();
while ( 1 )
{
v1 = v6++;
if ( (v12[v7] & 0x2004) != 0 )
break;
srca[strlen(srca)] = v7;
v13 = strlen(srca);
v7 = *((_BYTE *)src + v6);
srca[v13 + 1] = 0;
}
if ( v7 != 60 )
{
++v1;
srca[strlen(srca)] = v7;
}
func1(s, srca, &v22, &v23);
func0(srca, 30);
v5 = strlen((const char *)src);
goto LABEL_2;
}
v19 = (char *)src + v6;
++v1;
putchar(v7);
if ( *v19 == 10 )
{
v23 = 0;
func0(s, v22);
}
v6 = v1;
v5 = strlen((const char *)src);
if ( v1 >= v5 )
goto LABEL_10;
}
v19 = (char *)src + v6;
if ( strstr((const char *)src + v6, ">") )
{
putchar(62);
v5 = strlen((const char *)src);
}
else if ( strstr(v19, "<") )
{
putchar(60);
v5 = strlen((const char *)src);
}
v1 += strlen(haystack);
}
LABEL_10:
v8 = s;
puts(s);
free(v8);
}

original_code:
static void printHTML (char *value) {
  int i;
  int j;
  char str[strlen(value)];
  strcpy(str, value);
  char *tok;
  char *ptr;
  char *link;
  struct winsize term;
  ioctl(1, 0x5413, &term);
  int buf_sz = ++term.ws_col;
  int buf_len = 0;
  char *buf = (char *) malloc(buf_sz);
  makeNull(buf, buf_sz);
  int max_word_len = 30;
  char word[max_word_len];
  for (j = 0; j < max_word_len; j++)
    word[j] = '\0';
  for (i = 0; i < strlen(value); i++) {
    if (value[i] == '<') {
      tok = strtok(str + i, "<>");
      if (!strcmp(tok, "/p")) {
        printf("%s\n", buf);
        buf_len = 0;
        makeNull(buf, buf_sz);
      }
      else if (!strcmp(tok, "code") && flags.color) {
        if (flags.wrap)
          wrapper(buf, "\x1B[32m", &buf_sz, &buf_len, term.ws_col);
        else
          printf("%s", "\x1B[32m");
      }
      else if (!strcmp(tok, "/code") && flags.color) {
        if (flags.wrap)
          wrapper(buf, "\x1B[0m", &buf_sz, &buf_len, term.ws_col);
        else
         printf("%s", "\x1B[0m");
      }
      else if (!strcmp(tok, "li"))
        printf("\t");
      else if ((ptr = strstr(tok, "/a")) && link) {
        if (flags.wrap && flags.color) {
          wrapper(buf, "\x1B[36m", &buf_sz, &buf_len, term.ws_col);
          wrapper(buf, " <", &buf_sz, &buf_len, term.ws_col);
          wrapper(buf, link, &buf_sz, &buf_len, term.ws_col);
          wrapper(buf, ">", &buf_sz, &buf_len, term.ws_col);
          wrapper(buf, "\x1B[0m", &buf_sz, &buf_len, term.ws_col);
        }
        else if (flags.color)
          printf(" %s<%s>%s", "\x1B[36m", link, "\x1B[0m");
        else
          printf(" <%s> " , link);
      }
      else if ((link = strstr(tok, "http"))) {
        link[strlen(link) - 1] = '\0';
      }
      i += strlen(tok) + 1;
    }
    else if (value[i] == '&') {
      if (strstr(value + i, ">"))
        printf(">");
      else if (strstr(value + i, "<"))
        printf("<");
      i += strlen(tok) - 1;
    }
    else {
      if (value[i] == '>') continue;
      if (flags.wrap) {
        while (!((*__ctype_b_loc ())[(int) ((value[i]))] & (unsigned short int) _ISpunct) && !((*__ctype_b_loc ())[(int) ((value[i]))] & (unsigned short int) _ISspace)) {
          word[strlen(word)] = value[i];
          word[strlen(word) + 1] = '\0';
          i++;
        }
        if (value[i] == '<') i--;
        else
          word[strlen(word)] = value[i];
        wrapper(buf, word, &buf_sz, &buf_len, term.ws_col);
        makeNull(word, max_word_len);
      }
      else {
        printf("%c", value[i]);
        if (value[i] == '\n') {
          buf_len = 0;
          makeNull(buf, buf_sz);
        }
      }
    }
  }
  printf("%s\n", buf);
  free(buf);
}

canonical_original_code:
static void printHTML(char *value) {
  int i;
  int j;
  char str[-1];
  strcpy(str, value);
  char *tok;
  char *ptr;
  char *link;
  struct winsize term;
  ioctl(1, 0x5413, &term);
  int buf_sz = ++term.ws_col;
  int buf_len = 0;
  char *buf = (char *) malloc(buf_sz);
  makeNull(buf, buf_sz);
  int max_word_len = 30;
  char word[-1];
  for (j = 0; j < max_word_len; j++)
    word[j] = '\0';
  for (i = 0; i < strlen(value); i++) {
    if (value[i] == '<') {
      tok = strtok(str + i, "<>");
      if (!strcmp(tok, "/p")) {
        printf("%s\n", buf);
        buf_len = 0;
        makeNull(buf, buf_sz);
      }
      else if (!strcmp(tok, "code") && flags.color) {
        if (flags.wrap)
          wrapper(buf, "\x1B[32m", &buf_sz, &buf_len, term.ws_col);
        else
          printf("%s", "\x1B[32m");
      }
      else if (!strcmp(tok, "/code") && flags.color) {
        if (flags.wrap)
          wrapper(buf, "\x1B[0m", &buf_sz, &buf_len, term.ws_col);
        else
         printf("%s", "\x1B[0m");
      }
      else if (!strcmp(tok, "li"))
        printf("\t");
      else if ((ptr = strstr(tok, "/a")) && link) {
        if (flags.wrap && flags.color) {
          wrapper(buf, "\x1B[36m", &buf_sz, &buf_len, term.ws_col);
          wrapper(buf, " <", &buf_sz, &buf_len, term.ws_col);
          wrapper(buf, link, &buf_sz, &buf_len, term.ws_col);
          wrapper(buf, ">", &buf_sz, &buf_len, term.ws_col);
          wrapper(buf, "\x1B[0m", &buf_sz, &buf_len, term.ws_col);
        }
        else if (flags.color)
          printf(" %s<%s>%s", "\x1B[36m", link, "\x1B[0m");
        else
          printf(" <%s> " , link);
      }
      else if ((link = strstr(tok, "http"))) {
        link[strlen(link) - 1] = '\0';
      }
      i += strlen(tok) + 1;
    }
    else if (value[i] == '&') {
      if (strstr(value + i, ">"))
        printf(">");
      else if (strstr(value + i, "<"))
        printf("<");
      i += strlen(tok) - 1;
    }
    else {
      if (value[i] == '>') continue;
      if (flags.wrap) {
        while (!((*__ctype_b_loc ())[(int) ((value[i]))] & (unsigned short) _ISpunct) && !((*__ctype_b_loc ())[(int) ((value[i]))] & (unsigned short) _ISspace)) {
          word[strlen(word)] = value[i];
          word[strlen(word) + 1] = '\0';
          i++;
        }
        if (value[i] == '<') i--;
        else
          word[strlen(word)] = value[i];
        wrapper(buf, word, &buf_sz, &buf_len, term.ws_col);
        makeNull(word, max_word_len);
      }
      else {
        printf("%c", value[i]);
        if (value[i] == '\n') {
          buf_len = 0;
          makeNull(buf, buf_sz);
        }
      }
    }
  }
  printf("%s\n", buf);
  free(buf);
}

variable_types:
value
char *

variable_types: j int

variable_types:
str
char [-1]

variable_types:
tok
char *

variable_types:
ptr
char *

variable_types:
link
char *

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }

variable_types:
buf
char *

variable_types:
word
char [-1]


parse

decompiled_code:
__int64 parse()
{
streamFile();
xmlCleanupParser();
return xmlMemoryDump();
}

canonical_decompiled_code:
__int64 func5()
{
func4();
xmlCleanupParser();
return xmlMemoryDump();
}

original_code:
void parse () {
  streamFile();
  xmlCleanupParser();
  xmlMemoryDump();
}

canonical_original_code:
void parse() {
  streamFile();
  xmlCleanupParser();
  xmlMemoryDump();
}


decompiled_code:
void __fastcall __noreturn print_help(const char *a1)
{
printf("Usage: %s [OPTION]\n\n", a1);
puts("-b --brief");
puts("\tdo not print news\n");
puts("-c --color");
puts("\tcolorize output");
puts("\t set when STDOUT detected as being a terminal\n");
puts("-d --display [INTEGER]");
puts("\tspecify number of entries to display (newest first)");
puts("\t use 0 to display all entries (default)");
puts("\t use -b if you do not want to display any entries\n");
puts("-e --new");
puts("\tonly print new messages\n");
puts("-f --file [FILE]");
puts("\tspecify download location");
puts("\t default location is ~/.cache/archfeed/newss\n");
puts("-l --local");
puts("\tdo not download news (use local copy)\n");
puts("-n --nocolor");
puts("\tdo not colorize output\n");
puts("-r --nowrap");
puts("\tdo not wrap output");
puts("\t set when STDOUT is detected as not being a terminal\n");
puts("-o --force");
puts("\trun program without checking for new entries\n");
puts("-p --poll");
puts("\tissue header request and compare timestamps before proceeding");
puts("\t program exits if there are no new entries (default)\n");
puts("-s -skip");
puts("\tskips first n entries\n");
puts("-u --update");
puts("\tdownload news (default)\n");
puts("-v --verbose");
puts("\tprint news (default)\n");
puts("-w --wrap");
puts("\twrap output");
puts("\t set when STDOUT is detected as being a terminal\n");
puts("-h --help");
puts("\tdisplay this message and exit");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
printf("Usage: %s [OPTION]\n\n", a1);
puts("-b --brief");
puts("\tdo not print news\n");
puts("-c --color");
puts("\tcolorize output");
puts("\t set when STDOUT detected as being a terminal\n");
puts("-d --display [INTEGER]");
puts("\tspecify number of entries to display (newest first)");
puts("\t use 0 to display all entries (default)");
puts("\t use -b if you do not want to display any entries\n");
puts("-e --new");
puts("\tonly print new messages\n");
puts("-f --file [FILE]");
puts("\tspecify download location");
puts("\t default location is ~/.cache/archfeed/newss\n");
puts("-l --local");
puts("\tdo not download news (use local copy)\n");
puts("-n --nocolor");
puts("\tdo not colorize output\n");
puts("-r --nowrap");
puts("\tdo not wrap output");
puts("\t set when STDOUT is detected as not being a terminal\n");
puts("-o --force");
puts("\trun program without checking for new entries\n");
puts("-p --poll");
puts("\tissue header request and compare timestamps before proceeding");
puts("\t program exits if there are no new entries (default)\n");
puts("-s -skip");
puts("\tskips first n entries\n");
puts("-u --update");
puts("\tdownload news (default)\n");
puts("-v --verbose");
puts("\tprint news (default)\n");
puts("-w --wrap");
puts("\twrap output");
puts("\t set when STDOUT is detected as being a terminal\n");
puts("-h --help");
puts("\tdisplay this message and exit");
exit(1);
}

original_code:
static void print_help (char *program) {
  printf("Usage: %s [OPTION]\n\n", program);
  printf("-b --brief\n");
  printf("\tdo not print news\n\n");
  printf("-c --color\n");
  printf("\tcolorize output\n");
  printf("\t  set when STDOUT detected as being a terminal\n\n");
  printf("-d --display [INTEGER]\n");
  printf("\tspecify number of entries to display (newest first)\n");
  printf("\t  use 0 to display all entries (default)\n");
  printf("\t  use -b if you do not want to display any entries\n\n");
  printf("-e --new\n");
  printf("\tonly print new messages\n\n");
  printf("-f --file [FILE]\n");
  printf("\tspecify download location\n");
  printf("\t  default location is ~/.cache/archfeed/newss\n\n");
  printf("-l --local\n");
  printf("\tdo not download news (use local copy)\n\n");
  printf("-n --nocolor\n");
  printf("\tdo not colorize output\n\n");
  printf("-r --nowrap\n");
  printf("\tdo not wrap output\n");
  printf("\t  set when STDOUT is detected as not being a terminal\n\n");
  printf("-o --force\n");
  printf("\trun program without checking for new entries\n\n");
  printf("-p --poll\n");
  printf("\tissue header request and compare timestamps before proceeding\n");
  printf("\t  program exits if there are no new entries (default)\n\n");
  printf("-s -skip\n");
  printf("\tskips first n entries\n\n");
  printf("-u --update\n");
  printf("\tdownload news (default)\n\n");
  printf("-v --verbose\n");
  printf("\tprint news (default)\n\n");
  printf("-w --wrap\n");
  printf("\twrap output\n");
  printf("\t  set when STDOUT is detected as being a terminal\n\n");
  printf("-h --help\n");
  printf("\tdisplay this message and exit\n");
  exit(1);
}

canonical_original_code:
static void print_help(char *program) {
  printf("Usage: %s [OPTION]\n\n", program);
  printf("-b --brief\n");
  printf("\tdo not print news\n\n");
  printf("-c --color\n");
  printf("\tcolorize output\n");
  printf("\t  set when STDOUT detected as being a terminal\n\n");
  printf("-d --display [INTEGER]\n");
  printf("\tspecify number of entries to display (newest first)\n");
  printf("\t  use 0 to display all entries (default)\n");
  printf("\t  use -b if you do not want to display any entries\n\n");
  printf("-e --new\n");
  printf("\tonly print new messages\n\n");
  printf("-f --file [FILE]\n");
  printf("\tspecify download location\n");
  printf("\t  default location is ~/.cache/archfeed/newss\n\n");
  printf("-l --local\n");
  printf("\tdo not download news (use local copy)\n\n");
  printf("-n --nocolor\n");
  printf("\tdo not colorize output\n\n");
  printf("-r --nowrap\n");
  printf("\tdo not wrap output\n");
  printf("\t  set when STDOUT is detected as not being a terminal\n\n");
  printf("-o --force\n");
  printf("\trun program without checking for new entries\n\n");
  printf("-p --poll\n");
  printf("\tissue header request and compare timestamps before proceeding\n");
  printf("\t  program exits if there are no new entries (default)\n\n");
  printf("-s -skip\n");
  printf("\tskips first n entries\n\n");
  printf("-u --update\n");
  printf("\tdownload news (default)\n\n");
  printf("-v --verbose\n");
  printf("\tprint news (default)\n\n");
  printf("-w --wrap\n");
  printf("\twrap output\n");
  printf("\t  set when STDOUT is detected as being a terminal\n\n");
  printf("-h --help\n");
  printf("\tdisplay this message and exit\n");
  exit(1);
}

variable_types:
program
char *


xferinfo

decompiled_code:
__int64 __fastcall xferinfo(__int64 a1, int a2, __int64 a3)
{
int v4; // er12
int v5; // er13
int v6; // er12
int v8; // ebp
double v9; // [rsp+8h] [rbp-40h]
char v10[2]; // [rsp+18h] [rbp-30h] BYREF
unsigned __int16 v11; // [rsp+1Ah] [rbp-2Eh]

ioctl(1, 0x5413uLL, v10);
v4 = v11;
v5 = v11 - 7;
if ( a3 )
{
v9 = (double)(int)a3 / (double)a2;
LODWORD(a3) = (int)round((double)v5 * v9);
printf("%3.0f%% [", v9 * 100.0);
if ( (int)a3 <= 0 )
{
LODWORD(a3) = 0;
}
else
{
v8 = 0;
do
{
++v8;
putchar(61);
}
while ( (_DWORD)a3 != v8 );
}
}
else
{
printf("%3.0f%% [", 0.0);
}
if ( v5 > (int)a3 )
{
v6 = v4 - 7;
do
{
LODWORD(a3) = a3 + 1;
putchar(32);
}
while ( v6 != (_DWORD)a3 );
}
printf("]\r");
fflush(stdout);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int64 a3)
{
int v4; // er12
int v5; // er13
int v6; // er12
int v8; // ebp
double v9; // [rsp+8h] [rbp-40h]
char v10[2]; // [rsp+18h] [rbp-30h] BYREF
unsigned __int16 v11; // [rsp+1Ah] [rbp-2Eh]

ioctl(1, 0x5413uLL, v10);
v4 = v11;
v5 = v11 - 7;
if ( a3 )
{
v9 = (double)(int)a3 / (double)a2;
LODWORD(a3) = (int)round((double)v5 * v9);
printf("%3.0f%% [", v9 * 100.0);
if ( (int)a3 <= 0 )
{
LODWORD(a3) = 0;
}
else
{
v8 = 0;
do
{
++v8;
putchar(61);
}
while ( (_DWORD)a3 != v8 );
}
}
else
{
printf("%3.0f%% [", 0.0);
}
if ( v5 > (int)a3 )
{
v6 = v4 - 7;
do
{
LODWORD(a3) = a3 + 1;
putchar(32);
}
while ( v6 != (_DWORD)a3 );
}
printf("]\r");
fflush(stdout);
return 0LL;
}

original_code:
static int xferinfo (void *ptr,
                     curl_off_t dltotal, curl_off_t dlnow,
                     curl_off_t ultotal, curl_off_t ulnow) {
  struct winsize term;
  ioctl(1, 0x5413, &term);
  int bar_len = term.ws_col - 7;
  int bar_full;
  int i;
  double frac_down;
  if (dlnow == 0) {
    frac_down = 0;
    bar_full = 0;
  }
  else {
    frac_down = (double) dlnow / (double) dltotal;
    bar_full = round(frac_down * bar_len);
  }
  printf("%3.0f%% [", frac_down * 100);
  for (i = 0; i < bar_full; i++)
    printf("=");
  for ( ; i < bar_len; i++)
    printf(" ");
  printf("]\r");
  fflush(stdout);
  return 0;
}

canonical_original_code:
static int xferinfo(void *ptr, long dltotal, long dlnow, long ultotal, long ulnow) {
  struct winsize term;
  ioctl(1, 0x5413, &term);
  int bar_len = term.ws_col - 7;
  int bar_full;
  int i;
  double frac_down;
  if (dlnow == 0) {
    frac_down = 0;
    bar_full = 0;
  }
  else {
    frac_down = (double) dlnow / (double) dltotal;
    bar_full = round(frac_down * bar_len);
  }
  printf("%3.0f%% [", frac_down * 100);
  for (i = 0; i < bar_full; i++)
    printf("=");
  for ( ; i < bar_len; i++)
    printf(" ");
  printf("]\r");
  fflush(stdout);
  return 0;
}

variable_types:
ptr
void *

variable_types: dltotal long

variable_types: dlnow long

variable_types: ultotal long

variable_types: ulnow long

return_type: int

user_defined_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


decompiled_code:
__int64 __fastcall older_progress(__int64 a1, double a2, double a3)
{
return xferinfo(a1, (int)a2, (unsigned int)(int)a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, double a2, double a3)
{
return func1(a1, (int)a2, (unsigned int)(int)a3);
}

original_code:
static int older_progress (void *ptr,
                           double dltotal, double dlnow,
                           double ultotal, double ulnow) {
  return xferinfo(ptr,
                  (curl_off_t) dltotal,
                  (curl_off_t) dlnow,
                  (curl_off_t) ultotal,
                  (curl_off_t) ulnow);
}

canonical_original_code:
static int older_progress(void *ptr, double dltotal, double dlnow, double ultotal, double ulnow) {
  return xferinfo(ptr,
                  (long) dltotal,
                  (long) dlnow,
                  (long) ultotal,
                  (long) ulnow);
}

variable_types: dltotal double

variable_types: dlnow double

variable_types: ultotal double

variable_types: ulnow double


WriteMemoryCallback

decompiled_code:
size_t __fastcall WriteMemoryCallback(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v5; // r12
char *v6; // rax
_BYTE *v7; // rdx
size_t v8; // rax

v5 = a3 * a2;
v6 = (char *)realloc(*(void **)a4, a3 * a2 + *(_QWORD *)(a4 + 8) + 1);
*(_QWORD *)a4 = v6;
if ( !v6 )
{
fwrite("Not enough memory (realloc failed).\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
memcpy(&v6[*(_QWORD *)(a4 + 8)], src, v5);
v7 = *(_BYTE **)a4;
v8 = v5 + *(_QWORD *)(a4 + 8);
*(_QWORD *)(a4 + 8) = v8;
v7[v8] = 0;
return v5;
}

canonical_decompiled_code:
size_t __fastcall func0(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v5; // r12
char *v6; // rax
_BYTE *v7; // rdx
size_t v8; // rax

v5 = a3 * a2;
v6 = (char *)realloc(*(void **)a4, a3 * a2 + *(_QWORD *)(a4 + 8) + 1);
*(_QWORD *)a4 = v6;
if ( !v6 )
{
fwrite("Not enough memory (realloc failed).\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
memcpy(&v6[*(_QWORD *)(a4 + 8)], src, v5);
v7 = *(_BYTE **)a4;
v8 = v5 + *(_QWORD *)(a4 + 8);
*(_QWORD *)(a4 + 8) = v8;
v7[v8] = 0;
return v5;
}

original_code:
static size_t WriteMemoryCallback (void *contents, size_t size, size_t nmemb,
                                   void *userp) {
  size_t realsize = size * nmemb;
  struct MemoryStruct *mem = (struct MemoryStruct *) userp;
  mem->memory = realloc(mem->memory, mem->size + realsize + 1);
  if (mem->memory == ((void *)0)) {
    fprintf(stderr, "Not enough memory (realloc failed).\n");
    exit(1);
  }
  memcpy(&(mem->memory[mem->size]), contents, realsize);
  mem->size += realsize;
  mem->memory[mem->size] = 0;
  return realsize;
}

canonical_original_code:
static unsigned long WriteMemoryCallback(void *contents, unsigned long size, unsigned long nmemb, void *userp) {
  unsigned long realsize = size * nmemb;
  struct MemoryStruct *mem = (struct MemoryStruct *) userp;
  mem->memory = realloc(mem->memory, mem->size + realsize + 1);
  if (mem->memory == ((void *)0)) {
    fprintf(stderr, "Not enough memory (realloc failed).\n");
    exit(1);
  }
  memcpy(&(mem->memory[mem->size]), contents, realsize);
  mem->size += realsize;
  mem->memory[mem->size] = 0;
  return realsize;
}

variable_types:
contents
void *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
userp
void *

variable_types:
realsize
unsigned long

variable_types: struct MemoryStruct { char *memory; unsigned long size; } *

return_type: unsigned long


comparison

decompiled_code:
_BOOL8 __fastcall comparison(const char *a1)
{
char *v1; // rbp
time_t v2; // rax
__time_t v3; // rbp
struct tm v5; // [rsp+0h] [rbp-D8h] BYREF
struct stat v6; // [rsp+40h] [rbp-98h] BYREF

v1 = strstr(a1, "Last-Modified");
*strchr(v1, 10) = 0;
strptime(v1, "Last-Modified: %a, %d %b %Y %H:%M:%S GMT ", &v5);
v2 = mktime(&v5);
if ( v2 == -1 )
{
perror("Error");
exit(1);
}
v3 = v2;
if ( stat("/var/cache/pacman/pkg", &v6) == -1 )
{
perror("Error");
puts("test");
exit(1);
}
return v6.st_mtim.tv_sec < v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
char *v1; // rbp
time_t v2; // rax
__time_t v3; // rbp
struct tm v5; // [rsp+0h] [rbp-D8h] BYREF
struct stat v6; // [rsp+40h] [rbp-98h] BYREF

v1 = strstr(a1, "Last-Modified");
*strchr(v1, 10) = 0;
strptime(v1, "Last-Modified: %a, %d %b %Y %H:%M:%S GMT ", &v5);
v2 = mktime(&v5);
if ( v2 == -1 )
{
perror("Error");
exit(1);
}
v3 = v2;
if ( stat("/var/cache/pacman/pkg", &v6) == -1 )
{
perror("Error");
puts("test");
exit(1);
}
return v6.st_mtim.tv_sec < v3;
}

original_code:
static int comparison (char *memory) {
  const char *CACHE_DIR = "/var/cache/pacman/pkg";
  char *mod_str;
  char *ptr;
  struct stat cache;
  struct tm news_mod;
  time_t news_time;
  mod_str = strstr(memory, "Last-Modified");
  ptr = strchr(mod_str, '\n');
  ptr[0] = '\0';
  strptime(mod_str, "Last-Modified: %a, %d %b %Y %H:%M:%S GMT ", &news_mod);
  if ((news_time = mktime(&news_mod)) == -1) {
    perror("Error");
    exit(1);
  }
  if (stat(CACHE_DIR, &cache) == -1) {
    perror("Error");
    printf("test\n");
    exit(1);
  }
  if (news_time > cache.st_mtime)
    return 1;
  return 0;
}

canonical_original_code:
static int comparison(char *memory) {
  char *CACHE_DIR = "/var/cache/pacman/pkg";
  char *mod_str;
  char *ptr;
  struct stat cache;
  struct tm news_mod;
  long news_time;
  mod_str = strstr(memory, "Last-Modified");
  ptr = strchr(mod_str, '\n');
  ptr[0] = '\0';
  strptime(mod_str, "Last-Modified: %a, %d %b %Y %H:%M:%S GMT ", &news_mod);
  if ((news_time = mktime(&news_mod)) == -1) {
    perror("Error");
    exit(1);
  }
  if (stat(CACHE_DIR, &cache) == -1) {
    perror("Error");
    printf("test\n");
    exit(1);
  }
  if (news_time > cache.st_mtime)
    return 1;
  return 0;
}

variable_types:
memory
char *

variable_types:
ptr
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; }


getline

repo: vadali/casm

decompiled_code:
size_t __fastcall getline(char *s, int a2)
{
char *v2; // r8
size_t result; // rax

v2 = fgets(s, a2, stdin);
result = 0LL;
if ( v2 )
result = strlen(s);
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(char *s, int a2)
{
char *v2; // r8
size_t result; // rax

v2 = fgets(s, a2, stdin);
result = 0LL;
if ( v2 )
result = strlen(s);
return result;
}

original_code:
int getline(char *line, int max)
{
   if (fgets(line, max, stdin) == ((void *)0))
    return 0;
   else
    return strlen(line);
}

variable_types:
line
char *

variable_types: max int


contains

decompiled_code:
__int64 __fastcall contains(char a1, _BYTE *a2)
{
while ( *a2 )
{
if ( *a2 == a1 )
return 1LL;
++a2;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, _BYTE *a2)
{
while ( *a2 )
{
if ( *a2 == a1 )
return 1LL;
++a2;
}
return 0LL;
}

original_code:
int contains (char c, char* p) {
 if (*p=='\0') return 0;
 if (*p==c) return 1;
 return contains(c, p+1);
}

canonical_original_code:
int contains(char c, char *p) {
 if (*p=='\0') return 0;
 if (*p==c) return 1;
 return contains(c, p+1);
}

variable_types: c char

variable_types:
p
char *


strip

decompiled_code:
char *__fastcall strip(char *a1, _BYTE *a2)
{
char v3; // di
_BYTE *v4; // rdx
__int64 v5; // r8
char v6; // di

if ( !a1 )
return a1;
v3 = *a1;
if ( !v3 )
return a1;
if ( (unsigned int)contains(v3, a2) )
{
do
v6 = *(_BYTE *)++v5;
while ( v6 && (unsigned int)contains(v6, v4) );
}
return (char *)v5;
}

canonical_decompiled_code:
char *__fastcall func3(char *a1, _BYTE *a2)
{
char v3; // di
_BYTE *v4; // rdx
__int64 v5; // r8
char v6; // di

if ( !a1 )
return a1;
v3 = *a1;
if ( !v3 )
return a1;
if ( (unsigned int)func1(v3, a2) )
{
do
v6 = *(_BYTE *)++v5;
while ( v6 && (unsigned int)func1(v6, v4) );
}
return (char *)v5;
}

original_code:
char* strip(char* p,char* c) {
 while (p != ((void *)0) && *p!='\0' && contains(*p, c)) p++;
 return p;
}

canonical_original_code:
char *strip(char *p, char *c) {
 while (p != ((void *)0) && *p!='\0' && contains(*p, c)) p++;
 return p;
}

variable_types:
c
char *

return_type: char *


or

decompiled_code:
__int64 __fastcall or(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = a1;
if ( !a1 )
result = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = a1;
if ( !a1 )
result = a2;
return result;
}

original_code:
char* or (char* p1, char* p2) {
 if (p1 == ((void *)0)) return p2;
 return p1;
}

canonical_original_code:
char *or(char *p1, char *p2) {
 if (p1 == ((void *)0)) return p2;
 return p1;
}


allAlphas

decompiled_code:
__int64 __fastcall allAlphas(char *a1)
{
char *v1; // rdx
__int64 v2; // rdx

v1 = a1;
if ( a1 )
{
while ( *v1 )
{
if ( !isAlpha(v1) )
return v2;
v1 = (char *)(v2 + 1);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1)
{
char *v1; // rdx
__int64 v2; // rdx

v1 = a1;
if ( a1 )
{
while ( *v1 )
{
if ( !isAlpha(v1) )
return v2;
v1 = (char *)(v2 + 1);
}
}
return 0LL;
}

original_code:
char* allAlphas(char *p) {
 if (p==((void *)0) || *p=='\0') return ((void *)0);
 if (!isAlpha(p)) return p;
 return allAlphas(p+1);
}

canonical_original_code:
char *allAlphas(char *p) {
 if (p==((void *)0) || *p=='\0') return ((void *)0);
 if (!isAlpha(p)) return p;
 return allAlphas(p+1);
}


allAlphasOrDigit

decompiled_code:
char *__fastcall allAlphasOrDigit(char *a1)
{
char *v1; // rdx
char *v2; // rdx

v1 = a1;
if ( a1 )
{
while ( *v1 )
{
if ( !isAlpha(v1) && !isDigit(v2) )
return v2;
v1 = v2 + 1;
}
}
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func6(char *a1)
{
char *v1; // rdx
char *v2; // rdx

v1 = a1;
if ( a1 )
{
while ( *v1 )
{
if ( !isAlpha(v1) && !isDigit(v2) )
return v2;
v1 = v2 + 1;
}
}
return 0LL;
}

original_code:
char* allAlphasOrDigit(char *p) {
 if (p==((void *)0) || *p=='\0') return ((void *)0);
 if (!(isAlpha(p) || isDigit(p))) return p;
 return allAlphasOrDigit(p+1);
}

canonical_original_code:
char *allAlphasOrDigit(char *p) {
 if (p==((void *)0) || *p=='\0') return ((void *)0);
 if (!(isAlpha(p) || isDigit(p))) return p;
 return allAlphasOrDigit(p+1);
}


allString

decompiled_code:
char *__fastcall allString(char *a1)
{
char *i; // rbx

if ( !a1 )
return 0LL;
for ( i = a1; ; ++i )
{
if ( !*i )
return 0LL;
if ( !isStringChar(i) )
break;
}
return i;
}

canonical_decompiled_code:
char *__fastcall func9(char *a1)
{
char *i; // rbx

if ( !a1 )
return 0LL;
for ( i = a1; ; ++i )
{
if ( !*i )
return 0LL;
if ( !func8(i) )
break;
}
return i;
}

original_code:
char* allString(char *p) {
 if (p==((void *)0) || *p=='\0') return ((void *)0);
 if (!isStringChar(p)) return p;
 return allString(p+1);
}

canonical_original_code:
char *allString(char *p) {
 if (p==((void *)0) || *p=='\0') return ((void *)0);
 if (!isStringChar(p)) return p;
 return allString(p+1);
}


allDigits

decompiled_code:
__int64 __fastcall allDigits(char *a1)
{
char *v1; // rdx
__int64 v2; // rdx

v1 = a1;
if ( a1 )
{
while ( *v1 )
{
if ( !isDigit(v1) )
return v2;
v1 = (char *)(v2 + 1);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1)
{
char *v1; // rdx
__int64 v2; // rdx

v1 = a1;
if ( a1 )
{
while ( *v1 )
{
if ( !isDigit(v1) )
return v2;
v1 = (char *)(v2 + 1);
}
}
return 0LL;
}

original_code:
char* allDigits(char *p) {
 if (p==((void *)0) || *p=='\0') return ((void *)0);
 if (!isDigit(p)) return p;
 return allDigits(p+1);
}

canonical_original_code:
char *allDigits(char *p) {
 if (p==((void *)0) || *p=='\0') return ((void *)0);
 if (!isDigit(p)) return p;
 return allDigits(p+1);
}


getInteger

decompiled_code:
char *__fastcall getInteger(char *a1, _DWORD *a2)
{
char *v2; // r12
__int64 v3; // rax
__int64 v4; // r9
char *v5; // rax
char *v6; // rax
_DWORD *v7; // rcx
const char *v8; // r9
char v9; // bp

if ( !a1 )
return 0LL;
v2 = 0LL;
if ( *a1 )
{
v3 = oneOf(a1, byte_68F);
v5 = (char *)or(v3, v4);
v6 = (char *)allDigits(v5);
v2 = v6;
if ( v6 )
{
v2 = strip(v6, byte_692);
if ( !oneOf(v2, byte_694) || v8 == v2 )
{
*v7 = 2;
v2 = 0LL;
}
else
{
v9 = *v2;
*v2 = 0;
*a2 = (int)(float)atoi(v8);
*v2 = v9;
}
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func12(char *a1, _DWORD *a2)
{
char *v2; // r12
__int64 v3; // rax
__int64 v4; // r9
char *v5; // rax
char *v6; // rax
_DWORD *v7; // rcx
const char *v8; // r9
char v9; // bp

if ( !a1 )
return 0LL;
v2 = 0LL;
if ( *a1 )
{
v3 = func2(a1, byte_68F);
v5 = (char *)func4(v3, v4);
v6 = (char *)func11(v5);
v2 = v6;
if ( v6 )
{
v2 = func3(v6, byte_692);
if ( !func2(v2, byte_694) || v8 == v2 )
{
*v7 = 2;
v2 = 0LL;
}
else
{
v9 = *v2;
*v2 = 0;
*a2 = (int)(float)atoi(v8);
*v2 = v9;
}
}
}
return v2;
}

original_code:
char* getInteger(char*p, int* res, int* err) {
 char* e;
 char t;
 if (p==((void *)0) || *p == '\0') return ((void *)0);
 e = allDigits(or(oneOf(p, "+-"), p));
 if (e == ((void *)0)) return e;
 e = strip(e, " ");
 if ((!oneOf(e, "\n\r,"))||e==p) {
  *err = 2;
  return ((void *)0);
 }
 t = *e;
 *e = '\0';
 *res = (float)atoi(p);
 *e=t;
 return e;
}

canonical_original_code:
char *getInteger(char *p, int *res, int *err) {
 char *e;
 char t;
 if (p==((void *)0) || *p == '\0') return ((void *)0);
 e = allDigits(or(oneOf(p, "+-"), p));
 if (e == ((void *)0)) return e;
 e = strip(e, " ");
 if ((!oneOf(e, "\n\r,"))||e==p) {
  *err = 2;
  return ((void *)0);
 }
 t = *e;
 *e = '\0';
 *res = (float)atoi(p);
 *e=t;
 return e;
}

variable_types:
res
int *

variable_types:
err
int *

variable_types:
e
char *

variable_types: t char


getNumber

original_code:
char* getNumber(char*p, float* res, int* err) {
 char* e;
 char t;
 if (p==((void *)0) || *p == '\0') return ((void *)0);
 e = or(charIs(p, '-'), p);
 e = allDigits(e);
 e = or(charIs(e, '.'), e);
 e = or(allDigits(e), e);
 if (e == ((void *)0)) return e;
 e = strip(e, " ");
 if ((!charIs(e, ',') && !charIs(e, '\n'))||e==p) {
  *err = 2;
  return ((void *)0);
 }
 t = *e;
 *e = '\0';
 *res = (float)atof(p);
 *e=t;
 return e;
}

canonical_original_code:
char *getNumber(char *p, float *res, int *err) {
 char *e;
 char t;
 if (p==((void *)0) || *p == '\0') return ((void *)0);
 e = or(charIs(p, '-'), p);
 e = allDigits(e);
 e = or(charIs(e, '.'), e);
 e = or(allDigits(e), e);
 if (e == ((void *)0)) return e;
 e = strip(e, " ");
 if ((!charIs(e, ',') && !charIs(e, '\n'))||e==p) {
  *err = 2;
  return ((void *)0);
 }
 t = *e;
 *e = '\0';
 *res = (float)atof(p);
 *e=t;
 return e;
}

variable_types:
res
float *


trimNewline

decompiled_code:
const char *__fastcall trimNewline(const char *a1)
{
int v2; // eax
__int64 v3; // rbp
int v4; // ebx
__int64 v5; // rdi
int v6; // ebx

v2 = strlen(a1);
v3 = v2;
v4 = v2;
if ( oneOf(&a1[v2 - 1], &off_9C3) )
{
v5 = (__int64)&a1[v3 - 2];
LODWORD(v3) = v4 - 2;
v6 = v4 - 1;
v3 = (int)v3;
if ( !charIs(v5, 13LL) )
v3 = v6;
}
a1[v3] = 0;
return a1;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1)
{
int v2; // eax
__int64 v3; // rbp
int v4; // ebx
__int64 v5; // rdi
int v6; // ebx

v2 = strlen(a1);
v3 = v2;
v4 = v2;
if ( oneOf(&a1[v2 - 1], &off_9C3) )
{
v5 = (__int64)&a1[v3 - 2];
LODWORD(v3) = v4 - 2;
v6 = v4 - 1;
v3 = (int)v3;
if ( !charIs(v5, 13LL) )
v3 = v6;
}
a1[v3] = 0;
return a1;
}

original_code:
char* trimNewline(char* line)
{
 int l = strlen(line);
 int i=0;
 if (oneOf(&line[l-1],"\r\n")) {
  i++;
  if (charIs(&line[l-2],'\r')) i++;
 }
 line[l-i]='\0';
 return line;
}

canonical_original_code:
char *trimNewline(char *line)
{
 int l = strlen(line);
 int i = 0;
 if (oneOf(&line[l-1],"\r\n")) {
  i++;
  if (charIs(&line[l-2],'\r')) i++;
 }
 line[l-i]='\0';
 return line;
}

variable_types: l int

variable_types: i int


nothing

decompiled_code:
void nothing()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code: void nothing(addrVal* b){}

canonical_original_code: void nothing(struct addrVal *b){}

variable_types: struct addrVal { int val; enum addrType { a=expr, r=expr, e=expr } type; } *

user_defined_types: struct addrVal { int val; enum addrType type; }


main

canonical_name: main

repo: vadimg/embedder

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
char *i; // rax
char *v7; // [rsp+0h] [rbp-18h]
unsigned __int64 v8; // [rsp+8h] [rbp-10h]

v3 = get_symbol("data_txt");
v4 = v3;
if ( v3 )
{
v4 = 1;
printf("ERROR %d\n\n", v3);
}
else
{
for ( i = v7; (unsigned __int64)i < v8; v7 = i )
{
putchar(*i);
i = v7 + 1;
}
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
char *i; // rax
char *v7; // [rsp+0h] [rbp-18h]
unsigned __int64 v8; // [rsp+8h] [rbp-10h]

v3 = func7("data_txt");
v4 = v3;
if ( v3 )
{
v4 = 1;
printf("ERROR %d\n\n", v3);
}
else
{
for ( i = v7; (unsigned __int64)i < v8; v7 = i )
{
putchar(*i);
i = v7 + 1;
}
}
return v4;
}

original_code:
int main()
{
    char *start, *end;
    int rc = get_symbol("data_txt", (void**) &start, (void**) &end);
    if (rc) {
        printf("ERROR %d\n\n", rc);
        return 1;
    }
    while(start < end) {
        putchar(*start);
        ++start;
    }
    return 0;
}

canonical_original_code:
int main()
{
    char *start; char *end;
    int rc = get_symbol("data_txt", (void**) &start, (void**) &end);
    if (rc) {
        printf("ERROR %d\n\n", rc);
        return 1;
    }
    while(start < end) {
        putchar(*start);
        ++start;
    }
    return 0;
}

variable_types:
start
char *

variable_types:
end
char *

variable_types: rc int


original_code:
int get_symbol(const char* name, void** start, void** end) {
    void* s;
    void* e;
    char buffer[2048] = "_binary_";
    size_t start_len = sizeof("_binary_") - 1;
    size_t len = strlen(name) + start_len;
    if (sizeof(buffer) < len + sizeof("_start")) {
        *start = ((void *)0);
        *end = ((void *)0);
        return -1;
    }
    strcpy(buffer + start_len, name);
    strcpy(buffer + len, "_start");
    s = dlsym(((void *)0), buffer);
    if (!s) {
        *start = ((void *)0);
        *end = ((void *)0);
        return 1;
    }
    strcpy(buffer + len, "_end");
    e = dlsym(((void *)0), buffer);
    if (!e) {
        *start = ((void *)0);
        *end = ((void *)0);
        return 2;
    }
    *start = s;
    *end = e;
    return 0;
}

canonical_original_code:
int get_symbol(char *name, void **start, void **end) {
    void *s;
    void *e;
    char buffer[2048] = "_binary_";
    unsigned long start_len = sizeof("_binary_") - 1;
    unsigned long len = strlen(name) + start_len;
    if (sizeof(buffer) < len + sizeof("_start")) {
        *start = ((void *)0);
        *end = ((void *)0);
        return -1;
    }
    strcpy(buffer + start_len, name);
    strcpy(buffer + len, "_start");
    s = dlsym(((void *)0), buffer);
    if (!s) {
        *start = ((void *)0);
        *end = ((void *)0);
        return 1;
    }
    strcpy(buffer + len, "_end");
    e = dlsym(((void *)0), buffer);
    if (!e) {
        *start = ((void *)0);
        *end = ((void *)0);
        return 2;
    }
    *start = s;
    *end = e;
    return 0;
}

variable_types:
name
char *

variable_types:
start
void **

variable_types:
end
void **

variable_types:
s
void *

variable_types:
e
void *

variable_types:
buffer
char [2048]

variable_types:
len
unsigned long


repo: vakuum/tcptunnel

decompiled_code:
__int64 build_server()
{
const char *v0; // rdi
__int16 v1; // ax
int v2; // edx
int v3; // eax
int v4; // er8
__int64 result; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = options;
*(_OWORD *)&rc.sa_data[10] = 0LL;
v1 = atoi(v0);
*(_WORD *)&rc.sa_data[12] = _bswap_16(v1);
*(_WORD *)&rc.sa_data[10] = 2;
v3 = socket(2, 1, v2);
*(_DWORD *)&rc.sa_family = v3;
if ( v3 < 0 )
{
perror("build_server: socket()");
result = 1LL;
}
else
{
optval[0] = 1;
if ( setsockopt(v3, 1, 2, optval, 4u) < 0 )
{
perror("build_server: setsockopt(SO_REUSEADDR)");
result = 1LL;
}
else
{
if ( (settings & 8) != 0 )
*((_DWORD *)&rc + 4) = inet_addr(*(&options + 3));
if ( bind(*(int *)&rc.sa_family, (const struct sockaddr *)(unsigned int)((_DWORD)&rc + 12), 0x10u) < 0 )
{
perror("build_server: bind()");
result = 1LL;
}
else
{
v4 = listen(*(int *)&rc.sa_family, 1);
result = 0LL;
if ( v4 < 0 )
{
perror("build_server: listen()");
result = 1LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
const char *v0; // rdi
__int16 v1; // ax
int v2; // edx
int v3; // eax
int v4; // er8
__int64 result; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = options;
*(_OWORD *)&rc.sa_data[10] = 0LL;
v1 = atoi(v0);
*(_WORD *)&rc.sa_data[12] = func0(v1);
*(_WORD *)&rc.sa_data[10] = 2;
v3 = socket(2, 1, v2);
*(_DWORD *)&rc.sa_family = v3;
if ( v3 < 0 )
{
perror("build_server: socket()");
result = 1LL;
}
else
{
optval[0] = 1;
if ( setsockopt(v3, 1, 2, optval, 4u) < 0 )
{
perror("build_server: setsockopt(SO_REUSEADDR)");
result = 1LL;
}
else
{
if ( (settings & 8) != 0 )
*((_DWORD *)&rc + 4) = inet_addr(*(&options + 3));
if ( bind(*(int *)&rc.sa_family, (const struct sockaddr *)(unsigned int)((_DWORD)&rc + 12), 0x10u) < 0 )
{
perror("build_server: bind()");
result = 1LL;
}
else
{
v4 = listen(*(int *)&rc.sa_family, 1);
result = 0LL;
if ( v4 < 0 )
{
perror("build_server: listen()");
result = 1LL;
}
}
}
}
return result;
}

original_code:
int build_server(void)
{
 memset(&rc.server_addr, 0, sizeof(rc.server_addr));
 rc.server_addr.sin_port = htons(atoi(options.local_port));
 rc.server_addr.sin_family = 2;
 rc.server_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 rc.server_socket = socket(2, SOCK_STREAM, 0);
 if (rc.server_socket < 0)
 {
  perror("build_server: socket()");
  return 1;
 }
 int optval = 1;
 if (setsockopt(rc.server_socket, 1, 2, &optval, sizeof(optval)) < 0)
 {
  perror("build_server: setsockopt(SO_REUSEADDR)");
  return 1;
 }
 if (settings.bind_address)
 {
  rc.server_addr.sin_addr.s_addr = inet_addr(options.bind_address);
 }
 if (bind(rc.server_socket, (struct sockaddr *) &rc.server_addr, sizeof(rc.server_addr)) < 0)
 {
  perror("build_server: bind()");
  return 1;
 }
 if (listen(rc.server_socket, 1) < 0)
 {
  perror("build_server: listen()");
  return 1;
 }
 return 0;
}

canonical_original_code:
int build_server()
{
 memset(&rc.server_addr, 0, sizeof(rc.server_addr));
 rc.server_addr.sin_port = htons(atoi(options.local_port));
 rc.server_addr.sin_family = 2;
 rc.server_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 rc.server_socket = socket(2, SOCK_STREAM, 0);
 if (rc.server_socket < 0)
 {
  perror("build_server: socket()");
  return 1;
 }
 int optval = 1;
 if (setsockopt(rc.server_socket, 1, 2, &optval, sizeof(optval)) < 0)
 {
  perror("build_server: setsockopt(SO_REUSEADDR)");
  return 1;
 }
 if (settings.bind_address)
 {
  rc.server_addr.sin_addr.s_addr = inet_addr(options.bind_address);
 }
 if (bind(rc.server_socket, (struct sockaddr *) &rc.server_addr, sizeof(rc.server_addr)) < 0)
 {
  perror("build_server: bind()");
  return 1;
 }
 if (listen(rc.server_socket, 1) < 0)
 {
  perror("build_server: listen()");
  return 1;
 }
 return 0;
}

variable_types: optval int

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


decompiled_code:
__int64 build_tunnel()
{
struct hostent *v0; // rax
const char *v1; // rdi
struct hostent *v2; // rbx
__int16 v3; // ax
__int16 v4; // ax
size_t v5; // rdx
int v6; // eax
int v7; // er8
__int64 result; // rax

v0 = gethostbyname(*(&options + 1));
*((_QWORD *)&rc + 8) = v0;
if ( v0 )
{
v1 = *(&options + 2);
v2 = v0;
*(struct sockaddr *)((char *)&rc + 44) = 0LL;
*((_WORD *)&rc + 22) = 2;
v3 = atoi(v1);
v4 = _bswap_16(v3);
v5 = v2->h_length;
*((_WORD *)&rc + 23) = v4;
memcpy((void *)(unsigned int)((_DWORD)&rc + 48), *(const void **)v2->h_addr_list, v5);
v6 = socket(2, 1, 0);
*(_DWORD *)&rc.sa_data[6] = v6;
if ( v6 < 0 )
{
perror("build_tunnel: socket()");
result = 1LL;
}
else
{
v7 = connect(v6, (const struct sockaddr *)(unsigned int)((_DWORD)&rc + 44), 0x10u);
result = 0LL;
if ( v7 < 0 )
{
perror("build_tunnel: connect()");
result = 1LL;
}
}
}
else
{
perror("build_tunnel: gethostbyname()");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
struct hostent *v0; // rax
const char *v1; // rdi
struct hostent *v2; // rbx
__int16 v3; // ax
__int16 v4; // ax
size_t v5; // rdx
int v6; // eax
int v7; // er8
__int64 result; // rax

v0 = gethostbyname(*(&options + 1));
*((_QWORD *)&rc + 8) = v0;
if ( v0 )
{
v1 = *(&options + 2);
v2 = v0;
*(struct sockaddr *)((char *)&rc + 44) = 0LL;
*((_WORD *)&rc + 22) = 2;
v3 = atoi(v1);
v4 = func0(v3);
v5 = v2->h_length;
*((_WORD *)&rc + 23) = v4;
memcpy((void *)(unsigned int)((_DWORD)&rc + 48), *(const void **)v2->h_addr_list, v5);
v6 = socket(2, 1, 0);
*(_DWORD *)&rc.sa_data[6] = v6;
if ( v6 < 0 )
{
perror("build_tunnel: socket()");
result = 1LL;
}
else
{
v7 = connect(v6, (const struct sockaddr *)(unsigned int)((_DWORD)&rc + 44), 0x10u);
result = 0LL;
if ( v7 < 0 )
{
perror("build_tunnel: connect()");
result = 1LL;
}
}
}
else
{
perror("build_tunnel: gethostbyname()");
result = 1LL;
}
return result;
}

original_code:
int build_tunnel(void)
{
 rc.remote_host = gethostbyname(options.remote_host);
 if (rc.remote_host == ((void *)0))
 {
  perror("build_tunnel: gethostbyname()");
  return 1;
 }
 memset(&rc.remote_addr, 0, sizeof(rc.remote_addr));
 rc.remote_addr.sin_family = 2;
 rc.remote_addr.sin_port = htons(atoi(options.remote_port));
 memcpy(&rc.remote_addr.sin_addr.s_addr, rc.remote_host->h_addr_list[0], rc.remote_host->h_length);
 rc.remote_socket = socket(2, SOCK_STREAM, 0);
 if (rc.remote_socket < 0)
 {
  perror("build_tunnel: socket()");
  return 1;
 }
 if (connect(rc.remote_socket, (struct sockaddr *) &rc.remote_addr, sizeof(rc.remote_addr)) < 0)
 {
  perror("build_tunnel: connect()");
  return 1;
 }
 return 0;
}

canonical_original_code:
int build_tunnel()
{
 rc.remote_host = gethostbyname(options.remote_host);
 if (rc.remote_host == ((void *)0))
 {
  perror("build_tunnel: gethostbyname()");
  return 1;
 }
 memset(&rc.remote_addr, 0, sizeof(rc.remote_addr));
 rc.remote_addr.sin_family = 2;
 rc.remote_addr.sin_port = htons(atoi(options.remote_port));
 memcpy(&rc.remote_addr.sin_addr.s_addr, rc.remote_host->h_addr_list[0], rc.remote_host->h_length);
 rc.remote_socket = socket(2, SOCK_STREAM, 0);
 if (rc.remote_socket < 0)
 {
  perror("build_tunnel: socket()");
  return 1;
 }
 if (connect(rc.remote_socket, (struct sockaddr *) &rc.remote_addr, sizeof(rc.remote_addr)) < 0)
 {
  perror("build_tunnel: connect()");
  return 1;
 }
 return 0;
}


fd

decompiled_code:
__int64 fd()
{
unsigned int v0; // eax

v0 = *(_DWORD *)&rc.sa_data[2];
if ( *(_DWORD *)&rc.sa_data[6] >= v0 )
v0 = *(_DWORD *)&rc.sa_data[6];
return v0 + 1;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // eax

v0 = *(_DWORD *)&rc.sa_data[2];
if ( *(_DWORD *)&rc.sa_data[6] >= v0 )
v0 = *(_DWORD *)&rc.sa_data[6];
return v0 + 1;
}

original_code:
int fd(void)
{
 unsigned int fd = rc.client_socket;
 if (fd < rc.remote_socket)
 {
  fd = rc.remote_socket;
 }
 return fd + 1;
}

canonical_original_code:
int fd()
{
 unsigned int fd = rc.client_socket;
 if (fd < rc.remote_socket)
 {
  fd = rc.remote_socket;
 }
 return fd + 1;
}

variable_types:
fd
unsigned int


decompiled_code:
char *get_current_timestamp()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = localtime(&timer);
strftime(date_str_0, 0x14uLL, "%Y-%m-%d %H:%M:%S", v0);
return date_str_0;
}

canonical_decompiled_code:
char *func4()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v0 = localtime(&timer);
strftime(date_str_0, 0x14uLL, "%Y-%m-%d %H:%M:%S", v0);
return date_str_0;
}

original_code:
char *get_current_timestamp(void)
{
 static char date_str[20];
 time_t date;
 time(&date);
 strftime(date_str, sizeof(date_str), "%Y-%m-%d %H:%M:%S", localtime(&date));
 return date_str;
}

canonical_original_code:
char *get_current_timestamp()
{
 static char date_str[20];
 long date;
 time(&date);
 strftime(date_str, sizeof(date_str), "%Y-%m-%d %H:%M:%S", localtime(&date));
 return date_str;
}

variable_types: date long


decompiled_code:
__int64 wait_for_clients()
{
int v0; // eax
unsigned int v1; // er12
__int64 result; // rax
const char *v3; // r12
char *v4; // rax
char *v5; // r13
char *v6; // rax
char *v7; // r12
char *v8; // rax
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
v0 = accept(*(int *)&rc.sa_family, (struct sockaddr *)(unsigned int)((_DWORD)&rc + 28), addr_len);
*(_DWORD *)&rc.sa_data[2] = v0;
if ( v0 < 0 )
{
v1 = 1;
if ( *_errno_location() == 4 )
return v1;
perror("wait_for_clients: accept()");
result = 1LL;
}
else
{
if ( (settings & 0x10) != 0 )
{
v3 = *(&options + 4);
v4 = inet_ntoa(*(struct in_addr *)(&rc + 2));
if ( strcmp(v4, v3) )
{
if ( (settings & 0x80u) != 0 )
{
v7 = inet_ntoa(*(struct in_addr *)(&rc + 2));
v8 = get_current_timestamp();
printf("> %s tcptunnel: refused request from %s\n", v8, v7);
}
v1 = 1;
close(*(_DWORD *)&rc.sa_data[2]);
return v1;
}
v1 = 0;
if ( (settings & 0x80u) == 0 )
return v1;
}
else
{
v1 = 0;
if ( (settings & 0x80u) == 0 )
return v1;
}
v5 = inet_ntoa(*(struct in_addr *)(&rc + 2));
v6 = get_current_timestamp();
printf("> %s tcptunnel: request from %s\n", v6, v5);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // eax
unsigned int v1; // er12
__int64 result; // rax
const char *v3; // r12
char *v4; // rax
char *v5; // r13
char *v6; // rax
char *v7; // r12
char *v8; // rax
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
v0 = accept(*(int *)&rc.sa_family, (struct sockaddr *)(unsigned int)((_DWORD)&rc + 28), addr_len);
*(_DWORD *)&rc.sa_data[2] = v0;
if ( v0 < 0 )
{
v1 = 1;
if ( *_errno_location() == 4 )
return v1;
perror("wait_for_clients: accept()");
result = 1LL;
}
else
{
if ( (settings & 0x10) != 0 )
{
v3 = *(&options + 4);
v4 = inet_ntoa(*(struct in_addr *)(&rc + 2));
if ( strcmp(v4, v3) )
{
if ( (settings & 0x80u) != 0 )
{
v7 = inet_ntoa(*(struct in_addr *)(&rc + 2));
v8 = func4();
printf("> %s tcptunnel: refused request from %s\n", v8, v7);
}
v1 = 1;
close(*(_DWORD *)&rc.sa_data[2]);
return v1;
}
v1 = 0;
if ( (settings & 0x80u) == 0 )
return v1;
}
else
{
v1 = 0;
if ( (settings & 0x80u) == 0 )
return v1;
}
v5 = inet_ntoa(*(struct in_addr *)(&rc + 2));
v6 = func4();
printf("> %s tcptunnel: request from %s\n", v6, v5);
result = 0LL;
}
return result;
}

original_code:
int wait_for_clients(void)
{
 unsigned int client_addr_size;
 client_addr_size = sizeof(struct sockaddr_in);
 rc.client_socket = accept(rc.server_socket, (struct sockaddr *) &rc.client_addr, &client_addr_size);
 if (rc.client_socket < 0)
 {
  if ((*__errno_location ()) != 4)
  {
   perror("wait_for_clients: accept()");
  }
  return 1;
 }
 if (settings.client_address && (strcmp(inet_ntoa(rc.client_addr.sin_addr), options.client_address) != 0))
 {
  if (settings.log)
  {
   printf("> %s tcptunnel: refused request from %s\n", get_current_timestamp(), inet_ntoa(rc.client_addr.sin_addr));
  }
  close(rc.client_socket);
  return 1;
 }
 if (settings.log)
 {
  printf("> %s tcptunnel: request from %s\n", get_current_timestamp(), inet_ntoa(rc.client_addr.sin_addr));
 }
 return 0;
}

canonical_original_code:
int wait_for_clients()
{
 unsigned int client_addr_size;
 client_addr_size = sizeof(struct sockaddr_in);
 rc.client_socket = accept(rc.server_socket, (struct sockaddr *) &rc.client_addr, &client_addr_size);
 if (rc.client_socket < 0)
 {
  if ((*__errno_location ()) != 4)
  {
   perror("wait_for_clients: accept()");
  }
  return 1;
 }
 if (settings.client_address && (strcmp(inet_ntoa(rc.client_addr.sin_addr), options.client_address) != 0))
 {
  if (settings.log)
  {
   printf("> %s tcptunnel: refused request from %s\n", get_current_timestamp(), inet_ntoa(rc.client_addr.sin_addr));
  }
  close(rc.client_socket);
  return 1;
 }
 if (settings.log)
 {
  printf("> %s tcptunnel: request from %s\n", get_current_timestamp(), inet_ntoa(rc.client_addr.sin_addr));
 }
 return 0;
}

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


decompiled_code:
__int64 use_tunnel()
{
size_t v0; // r14
void *v1; // rsp
int v2; // edi
int v3; // eax
int v4; // ecx
int v5; // eax
int v6; // ecx
int v7; // eax
fd_set *v8; // rdx
fd_set *v9; // rcx
struct timeval *v10; // r8
int v11; // edi
int v12; // eax
int v13; // eax
unsigned int v14; // er15
size_t v15; // r15
char *v16; // rax
int v18; // eax
int v19; // edi
size_t v20; // r15
const char *v21; // rdi
fd_set v22; // [rsp+0h] [rbp-B0h] BYREF
__int64 v23; // [rsp+80h] [rbp-30h] BYREF

v0 = *((unsigned int *)&options + 10);
v1 = alloca(16 * ((v0 + 15) >> 4));
while ( 1 )
{
memset(&v22, 0, sizeof(v22));
v4 = *(_DWORD *)&rc.sa_data[2];
v5 = v4 + 63;
if ( v4 >= 0 )
v5 = *(_DWORD *)&rc.sa_data[2];
v6 = *(_DWORD *)&rc.sa_data[6];
v22.fds_bits[v5 >> 6] |= 1LL << (*(_DWORD *)&rc.sa_data[2] % 64);
v22.fds_bits[v6 / 64] |= 1LL << (v6 % 64);
v7 = fd(&v23, &v22, 0LL, 0LL, 0LL);
if ( select(v7, &v22, v8, v9, v10) < 0 )
{
v14 = 0;
perror("use_tunnel: select()");
return v14;
}
v11 = *(_DWORD *)&rc.sa_data[2];
v12 = v11 + 63;
if ( v11 >= 0 )
v12 = *(_DWORD *)&rc.sa_data[2];
if ( (v22.fds_bits[v12 >> 6] & (1LL << (*(_DWORD *)&rc.sa_data[2] % 64))) == 0 )
goto LABEL_2;
v13 = recv(v11, &v22, v0, 0);
v14 = v13;
if ( v13 < 0 )
{
v21 = "use_tunnel: recv(rc.client_socket)";
LABEL_22:
perror(v21);
v14 = 1;
close(*(_DWORD *)&rc.sa_data[2]);
close(*(_DWORD *)&rc.sa_data[6]);
return v14;
}
if ( !v13 )
break;
v15 = v13;
send(*(_DWORD *)&rc.sa_data[6], &v22, v13, 0);
if ( (settings & 0x80u) != 0 )
{
v16 = get_current_timestamp();
printf("> %s > ", v16);
fwrite(&v22, 1uLL, v15, stdout);
fflush(stdout);
}
LABEL_2:
v2 = *(_DWORD *)&rc.sa_data[6];
v3 = v2 + 63;
if ( v2 >= 0 )
v3 = *(_DWORD *)&rc.sa_data[6];
if ( (v22.fds_bits[v3 >> 6] & (1LL << (*(_DWORD *)&rc.sa_data[6] % 64))) != 0 )
{
v18 = recv(v2, &v22, v0, 0);
v14 = v18;
if ( v18 < 0 )
{
v21 = "use_tunnel: recv(rc.remote_socket)";
goto LABEL_22;
}
v19 = *(_DWORD *)&rc.sa_data[2];
if ( !v18 )
{
close(v19);
close(*(_DWORD *)&rc.sa_data[6]);
return v14;
}
v20 = v18;
send(v19, &v22, v18, 0);
if ( (settings & 0x80u) != 0 )
{
fwrite(&v22, 1uLL, v20, stdout);
fflush(stdout);
}
}
}
close(*(_DWORD *)&rc.sa_data[2]);
close(*(_DWORD *)&rc.sa_data[6]);
return v14;
}

canonical_decompiled_code:
__int64 func6()
{
size_t v0; // r14
void *v1; // rsp
int v2; // edi
int v3; // eax
int v4; // ecx
int v5; // eax
int v6; // ecx
int v7; // eax
fd_set *v8; // rdx
fd_set *v9; // rcx
struct timeval *v10; // r8
int v11; // edi
int v12; // eax
int v13; // eax
unsigned int v14; // er15
size_t v15; // r15
char *v16; // rax
int v18; // eax
int v19; // edi
size_t v20; // r15
const char *v21; // rdi
fd_set v22; // [rsp+0h] [rbp-B0h] BYREF
__int64 v23; // [rsp+80h] [rbp-30h] BYREF

v0 = *((unsigned int *)&options + 10);
v1 = alloca(16 * ((v0 + 15) >> 4));
while ( 1 )
{
memset(&v22, 0, sizeof(v22));
v4 = *(_DWORD *)&rc.sa_data[2];
v5 = v4 + 63;
if ( v4 >= 0 )
v5 = *(_DWORD *)&rc.sa_data[2];
v6 = *(_DWORD *)&rc.sa_data[6];
v22.fds_bits[v5 >> 6] |= 1LL << (*(_DWORD *)&rc.sa_data[2] % 64);
v22.fds_bits[v6 / 64] |= 1LL << (v6 % 64);
v7 = func3(&v23, &v22, 0LL, 0LL, 0LL);
if ( select(v7, &v22, v8, v9, v10) < 0 )
{
v14 = 0;
perror("use_tunnel: select()");
return v14;
}
v11 = *(_DWORD *)&rc.sa_data[2];
v12 = v11 + 63;
if ( v11 >= 0 )
v12 = *(_DWORD *)&rc.sa_data[2];
if ( (v22.fds_bits[v12 >> 6] & (1LL << (*(_DWORD *)&rc.sa_data[2] % 64))) == 0 )
goto LABEL_2;
v13 = recv(v11, &v22, v0, 0);
v14 = v13;
if ( v13 < 0 )
{
v21 = "use_tunnel: recv(rc.client_socket)";
LABEL_22:
perror(v21);
v14 = 1;
close(*(_DWORD *)&rc.sa_data[2]);
close(*(_DWORD *)&rc.sa_data[6]);
return v14;
}
if ( !v13 )
break;
v15 = v13;
send(*(_DWORD *)&rc.sa_data[6], &v22, v13, 0);
if ( (settings & 0x80u) != 0 )
{
v16 = func4();
printf("> %s > ", v16);
fwrite(&v22, 1uLL, v15, stdout);
fflush(stdout);
}
LABEL_2:
v2 = *(_DWORD *)&rc.sa_data[6];
v3 = v2 + 63;
if ( v2 >= 0 )
v3 = *(_DWORD *)&rc.sa_data[6];
if ( (v22.fds_bits[v3 >> 6] & (1LL << (*(_DWORD *)&rc.sa_data[6] % 64))) != 0 )
{
v18 = recv(v2, &v22, v0, 0);
v14 = v18;
if ( v18 < 0 )
{
v21 = "use_tunnel: recv(rc.remote_socket)";
goto LABEL_22;
}
v19 = *(_DWORD *)&rc.sa_data[2];
if ( !v18 )
{
close(v19);
close(*(_DWORD *)&rc.sa_data[6]);
return v14;
}
v20 = v18;
send(v19, &v22, v18, 0);
if ( (settings & 0x80u) != 0 )
{
fwrite(&v22, 1uLL, v20, stdout);
fflush(stdout);
}
}
}
close(*(_DWORD *)&rc.sa_data[2]);
close(*(_DWORD *)&rc.sa_data[6]);
return v14;
}

original_code:
int use_tunnel(void)
{
 fd_set io;
 char buffer[options.buffer_size];
 for (;;)
 {
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&io)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&io)->__fds_bits)[((rc.client_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((rc.client_socket) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&io)->__fds_bits)[((rc.remote_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((rc.remote_socket) % (8 * (int) sizeof (__fd_mask)))))));
  if (select(fd(), &io, ((void *)0), ((void *)0), ((void *)0)) < 0)
  {
   perror("use_tunnel: select()");
   break;
  }
  if (((((&io)->__fds_bits)[((rc.client_socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((rc.client_socket) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   int count = recv(rc.client_socket, buffer, sizeof(buffer), 0);
   if (count < 0)
   {
    perror("use_tunnel: recv(rc.client_socket)");
    close(rc.client_socket);
    close(rc.remote_socket);
    return 1;
   }
   if (count == 0)
   {
    close(rc.client_socket);
    close(rc.remote_socket);
    return 0;
   }
   send(rc.remote_socket, buffer, count, 0);
   if (settings.log)
   {
    printf("> %s > ", get_current_timestamp());
    fwrite(buffer, sizeof(char), count, stdout);
    fflush(stdout);
   }
  }
  if (((((&io)->__fds_bits)[((rc.remote_socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((rc.remote_socket) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   int count = recv(rc.remote_socket, buffer, sizeof(buffer), 0);
   if (count < 0)
   {
    perror("use_tunnel: recv(rc.remote_socket)");
    close(rc.client_socket);
    close(rc.remote_socket);
    return 1;
   }
   if (count == 0)
   {
    close(rc.client_socket);
    close(rc.remote_socket);
    return 0;
   }
   send(rc.client_socket, buffer, count, 0);
   if (settings.log)
   {
    fwrite(buffer, sizeof(char), count, stdout);
    fflush(stdout);
   }
  }
 }
 return 0;
}

canonical_original_code:
int use_tunnel()
{
 struct fd_set io;
 char buffer[-1];
 for (;;)
 {
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&io)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&io)->__fds_bits)[((rc.client_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((rc.client_socket) % (8 * (int) sizeof (__fd_mask)))))));
  ((void) (((&io)->__fds_bits)[((rc.remote_socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((rc.remote_socket) % (8 * (int) sizeof (__fd_mask)))))));
  if (select(fd(), &io, ((void *)0), ((void *)0), ((void *)0)) < 0)
  {
   perror("use_tunnel: select()");
   break;
  }
  if (((((&io)->__fds_bits)[((rc.client_socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((rc.client_socket) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   int count = recv(rc.client_socket, buffer, sizeof(buffer), 0);
   if (count < 0)
   {
    perror("use_tunnel: recv(rc.client_socket)");
    close(rc.client_socket);
    close(rc.remote_socket);
    return 1;
   }
   if (count == 0)
   {
    close(rc.client_socket);
    close(rc.remote_socket);
    return 0;
   }
   send(rc.remote_socket, buffer, count, 0);
   if (settings.log)
   {
    printf("> %s > ", get_current_timestamp());
    fwrite(buffer, sizeof(char), count, stdout);
    fflush(stdout);
   }
  }
  if (((((&io)->__fds_bits)[((rc.remote_socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((rc.remote_socket) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   int count = recv(rc.remote_socket, buffer, sizeof(buffer), 0);
   if (count < 0)
   {
    perror("use_tunnel: recv(rc.remote_socket)");
    close(rc.client_socket);
    close(rc.remote_socket);
    return 1;
   }
   if (count == 0)
   {
    close(rc.client_socket);
    close(rc.remote_socket);
    return 0;
   }
   send(rc.client_socket, buffer, count, 0);
   if (settings.log)
   {
    fwrite(buffer, sizeof(char), count, stdout);
    fflush(stdout);
   }
  }
 }
 return 0;
}

variable_types:
io
struct fd_set { long __fds_bits[-1]; }

variable_types:
buffer
char [-1]

variable_types: count int


decompiled_code:
__int64 handle_tunnel()
{
__int64 result; // rax

result = build_tunnel();
if ( !(_DWORD)result )
result = use_tunnel();
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax

result = func2();
if ( !(_DWORD)result )
result = func6();
return result;
}

original_code:
void handle_tunnel(void)
{
 if (build_tunnel() == 0)
 {
  use_tunnel();
 }
}

canonical_original_code:
void handle_tunnel()
{
 if (build_tunnel() == 0)
 {
  use_tunnel();
 }
}


decompiled_code:
int handle_client()
{
if ( (settings & 0x40) == 0 )
return handle_tunnel();
if ( !fork() )
{
close(*(int *)&rc.sa_family);
handle_tunnel();
exit(0);
}
return close(*(_DWORD *)&rc.sa_data[2]);
}

canonical_decompiled_code:
int func8()
{
if ( (settings & 0x40) == 0 )
return func7();
if ( !fork() )
{
close(*(int *)&rc.sa_family);
func7();
exit(0);
}
return close(*(_DWORD *)&rc.sa_data[2]);
}

original_code:
void handle_client(void)
{
 if (settings.fork)
 {
  if (fork() == 0)
  {
   close(rc.server_socket);
   handle_tunnel();
   exit(0);
  }
  close(rc.client_socket);
 }
 else
 {
  handle_tunnel();
 }
}

canonical_original_code:
void handle_client()
{
 if (settings.fork)
 {
  if (fork() == 0)
  {
   close(rc.server_socket);
   handle_tunnel();
   exit(0);
  }
  close(rc.client_socket);
 }
 else
 {
  handle_tunnel();
 }
}


decompiled_code:
int print_usage()
{
return fprintf(stderr, "Usage: %s [options]\n\n", (const char *)name);
}

canonical_decompiled_code:
int func9()
{
return fprintf(stderr, "Usage: %s [options]\n\n", (const char *)name);
}

original_code:
void print_usage(void)
{
 fprintf(stderr, "Usage: %s [options]\n\n", name);
}

canonical_original_code:
void print_usage()
{
 fprintf(stderr, "Usage: %s [options]\n\n", name);
}


decompiled_code:
int print_helpinfo()
{
return fprintf(stderr, "Try `%s --help' for more options\n", (const char *)name);
}

canonical_decompiled_code:
int func10()
{
return fprintf(stderr, "Try `%s --help' for more options\n", (const char *)name);
}

original_code:
void print_helpinfo(void)
{
 fprintf(stderr, "Try `%s --help' for more options\n", name);
}

canonical_original_code:
void print_helpinfo()
{
 fprintf(stderr, "Try `%s --help' for more options\n", name);
}


decompiled_code:
size_t print_help()
{
return fwrite(
"Options:\n"
" --version\n"
" --help\n"
"\n"
" --local-port=PORT local port\n"
" --remote-port=PORT remote port\n"
" --remote-host=HOST remote host\n"
" --bind-address=IP bind address\n"
" --client-address=IP only accept connections from this address\n"
" --buffer-size=BYTES buffer size\n"
" --fork fork-based concurrency\n"
" --log\n"
" --stay-alive\n"
"\n"
"\n",
1uLL,
0x156uLL,
stderr);
}

canonical_decompiled_code:
size_t func11()
{
return fwrite(
"Options:\n"
" --version\n"
" --help\n"
"\n"
" --local-port=PORT local port\n"
" --remote-port=PORT remote port\n"
" --remote-host=HOST remote host\n"
" --bind-address=IP bind address\n"
" --client-address=IP only accept connections from this address\n"
" --buffer-size=BYTES buffer size\n"
" --fork fork-based concurrency\n"
" --log\n"
" --stay-alive\n"
"\n"
"\n",
1uLL,
0x156uLL,
stderr);
}

original_code:
void print_help(void)
{
 fprintf(stderr, "Options:\n  --version\n  --help\n\n  --local-port=PORT    local port\n  --remote-port=PORT   remote port\n  --remote-host=HOST   remote host\n  --bind-address=IP    bind address\n  --client-address=IP  only accept connections from this address\n  --buffer-size=BYTES  buffer size\n"
"  --fork               fork-based concurrency\n"
"  --log\n  --stay-alive\n\n\n");
}

canonical_original_code:
void print_help()
{
 fprintf(stderr, "Options:\n  --version\n  --help\n\n  --local-port=PORT    local port\n  --remote-port=PORT   remote port\n  --remote-host=HOST   remote host\n  --bind-address=IP    bind address\n  --client-address=IP  only accept connections from this address\n  --buffer-size=BYTES  buffer size\n"
"  --fork               fork-based concurrency\n"
"  --log\n  --stay-alive\n\n\n");
}


decompiled_code:
size_t print_version()
{
return fwrite(
"tcptunnel v0.8 Copyright (C) 2000-2021 Clemens Fuchslocher\n"
"\n"
"This program is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"GNU General Public License for more details.\n"
"\n"
"Written by Clemens Fuchslocher <clemens@vakuumverpackt.de>\n",
1uLL,
0x162uLL,
stderr);
}

canonical_decompiled_code:
size_t func12()
{
return fwrite(
"tcptunnel v0.8 Copyright (C) 2000-2021 Clemens Fuchslocher\n"
"\n"
"This program is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"GNU General Public License for more details.\n"
"\n"
"Written by Clemens Fuchslocher <clemens@vakuumverpackt.de>\n",
1uLL,
0x162uLL,
stderr);
}

original_code:
void print_version(void)
{
 fprintf(stderr, "tcptunnel v" "0.8" " Copyright (C) 2000-2021 Clemens Fuchslocher\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nWritten by Clemens Fuchslocher <clemens@vakuumverpackt.de>\n");
}

canonical_original_code:
void print_version()
{
 fprintf(stderr, "tcptunnel v" "0.8" " Copyright (C) 2000-2021 Clemens Fuchslocher\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nWritten by Clemens Fuchslocher <clemens@vakuumverpackt.de>\n");
}


decompiled_code:
int __fastcall print_missing(const char *a1)
{
print_usage();
fprintf(stderr, "%s: %s\n", (const char *)name, a1);
return print_helpinfo();
}

canonical_decompiled_code:
int __fastcall func13(const char *a1)
{
func9();
fprintf(stderr, "%s: %s\n", (const char *)name, a1);
return func10();
}

original_code:
void print_missing(const char *message)
{
 print_usage();
 fprintf(stderr, "%s: %s\n", name, message);
 print_helpinfo();
}

canonical_original_code:
void print_missing(char *message)
{
 print_usage();
 fprintf(stderr, "%s: %s\n", name, message);
 print_helpinfo();
}

variable_types:
message
char *


decompiled_code:
__int64 __fastcall set_options(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax
int v4; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

*((_DWORD *)&options + 10) = 4096;
while ( 2 )
{
v2 = getopt_long(argc, argv, &shortopts, &long_options, longind);
switch ( v2 )
{
case '?':
print_usage();
print_helpinfo();
exit(0);
case 'a':
LOBYTE(settings) = settings | 1;
options = optarg;
continue;
case 'b':
LOBYTE(settings) = settings | 4;
*(&options + 2) = optarg;
continue;
case 'c':
LOBYTE(settings) = settings | 2;
*(&options + 1) = optarg;
continue;
case 'd':
LOBYTE(settings) = settings | 8;
*(&options + 3) = optarg;
continue;
case 'e':
LOBYTE(settings) = settings | 0x10;
*(&options + 4) = optarg;
continue;
case 'f':
v4 = atoi(optarg);
LOBYTE(settings) = settings | 0x20;
*((_DWORD *)&options + 10) = v4;
continue;
case 'g':
settings |= 0x140u;
continue;
case 'h':
LOBYTE(settings) = settings | 0x80;
continue;
case 'i':
HIBYTE(settings) |= 1u;
continue;
case 'j':
print_usage();
print_help();
exit(0);
case 'k':
print_version();
exit(0);
default:
if ( v2 != -1 )
continue;
result = (unsigned __int8)settings;
if ( (settings & 1) == 0 )
{
print_missing("missing '--local-port=' option.");
exit(1);
}
if ( (settings & 4) == 0 )
{
print_missing("missing '--remote-port=' option.");
exit(1);
}
if ( (settings & 2) == 0 )
{
print_missing("missing '--remote-host=' option.");
exit(1);
}
return result;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func14(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax
int v4; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

*((_DWORD *)&options + 10) = 4096;
while ( 2 )
{
v2 = getopt_long(argc, argv, &shortopts, &long_options, longind);
switch ( v2 )
{
case '?':
func9();
func10();
exit(0);
case 'a':
LOBYTE(settings) = settings | 1;
options = optarg;
continue;
case 'b':
LOBYTE(settings) = settings | 4;
*(&options + 2) = optarg;
continue;
case 'c':
LOBYTE(settings) = settings | 2;
*(&options + 1) = optarg;
continue;
case 'd':
LOBYTE(settings) = settings | 8;
*(&options + 3) = optarg;
continue;
case 'e':
LOBYTE(settings) = settings | 0x10;
*(&options + 4) = optarg;
continue;
case 'f':
v4 = atoi(optarg);
LOBYTE(settings) = settings | 0x20;
*((_DWORD *)&options + 10) = v4;
continue;
case 'g':
settings |= 0x140u;
continue;
case 'h':
LOBYTE(settings) = settings | 0x80;
continue;
case 'i':
HIBYTE(settings) |= 1u;
continue;
case 'j':
func9();
func11();
exit(0);
case 'k':
func12();
exit(0);
default:
if ( v2 != -1 )
continue;
result = (unsigned __int8)settings;
if ( (settings & 1) == 0 )
{
func13("missing '--local-port=' option.");
exit(1);
}
if ( (settings & 4) == 0 )
{
func13("missing '--remote-port=' option.");
exit(1);
}
if ( (settings & 2) == 0 )
{
func13("missing '--remote-host=' option.");
exit(1);
}
return result;
}
}
}

original_code:
void set_options(int argc, char *argv[])
{
 int opt;
 int index;
 options.buffer_size = 4096;
 do
 {
  opt = getopt_long(argc, argv, "", long_options, &index);
  switch (opt)
  {
   case 'a':
   {
    options.local_port = optarg;
    settings.local_port = 1;
    break;
   }
   case 'b':
   {
    options.remote_port = optarg;
    settings.remote_port = 1;
    break;
   }
   case 'c':
   {
    options.remote_host = optarg;
    settings.remote_host = 1;
    break;
   }
   case 'd':
   {
    options.bind_address = optarg;
    settings.bind_address = 1;
    break;
   }
   case 'f':
   {
    options.buffer_size = atoi(optarg);
    settings.buffer_size = 1;
    break;
   }
   case 'e':
   {
    options.client_address = optarg;
    settings.client_address = 1;
    break;
   }
   case 'g':
   {
    settings.fork = 1;
    settings.stay_alive = 1;
    break;
   }
   case 'h':
   {
    settings.log = 1;
    break;
   }
   case 'i':
   {
    settings.stay_alive = 1;
    break;
   }
   case 'j':
   {
    print_usage();
    print_help();
    exit(0);
   }
   case 'k':
   {
    print_version();
    exit(0);
   }
   case '?':
   {
    print_usage();
    print_helpinfo();
    exit(0);
   }
  }
 }
 while (opt != -1);
 if (!settings.local_port)
 {
  print_missing("missing '--local-port=' option.");
  exit(1);
 }
 if (!settings.remote_port)
 {
  print_missing("missing '--remote-port=' option.");
  exit(1);
 }
 if (!settings.remote_host)
 {
  print_missing("missing '--remote-host=' option.");
  exit(1);
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: index int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
name = (__int64)*argv;
set_options(argc, (char **)argv);
if ( (unsigned int)build_server() == 1 )
exit(1);
signal(17, (__sighandler_t)((char *)_bswap_16 + 1));
do
{
while ( (unsigned int)wait_for_clients() )
{
if ( (settings & 0x100) == 0 )
goto LABEL_6;
}
handle_client();
}
while ( (settings & 0x100) != 0 );
LABEL_6:
close(*(int *)&rc.sa_family);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
name = (__int64)*argv;
func14(argc, (char **)argv);
if ( (unsigned int)func1() == 1 )
exit(1);
signal(17, (__sighandler_t)((char *)_bswap_16 + 1));
do
{
while ( (unsigned int)func5() )
{
if ( (settings & 0x100) == 0 )
goto LABEL_6;
}
func8();
}
while ( (settings & 0x100) != 0 );
LABEL_6:
close(*(int *)&rc.sa_family);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 name = argv[0];
 set_options(argc, argv);
 if (build_server() == 1)
 {
  exit(1);
 }
 signal(17, ((__sighandler_t) 1));
 do
 {
  if (wait_for_clients() == 0)
  {
   handle_client();
  }
 }
 while (settings.stay_alive);
 close(rc.server_socket);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 name = argv[0];
 set_options(argc, argv);
 if (build_server() == 1)
 {
  exit(1);
 }
 signal(17, ((void (*)(int)) 1));
 do
 {
  if (wait_for_clients() == 0)
  {
   handle_client();
  }
 }
 while (settings.stay_alive);
 close(rc.server_socket);
 return 0;
}


repo: valdyn/autofire

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
KeyCode v3; // al
char *v4; // r14
KeySym v5; // rax
unsigned int v6; // er13
KeySym v7; // rax
unsigned int v8; // er12
KeySym v9; // rax
unsigned int v10; // ebp
KeySym v11; // rax
unsigned int v12; // ebx
char *v14; // rax

display = XOpenDisplay(0LL);
if ( !display )
{
v14 = XDisplayName(0LL);
printf("Cannot connect to X server %s\n", v14);
exit(-1);
}
if ( argc <= 1 )
{
fprintf(stderr, "Usage: %s %s \n", *argv, "<KeyboardName>");
exit(-1);
}
v3 = XKeysymToKeycode(display, 0xFFC9uLL);
XGrabKey(display, v3, 0x8000u, display->screens[(__int64)display->default_screen].root, 0, 1, 1);
v4 = (char *)argv[1];
v5 = XStringToKeysym("1");
v6 = XKeysymToKeycode(display, v5);
v7 = XStringToKeysym("2");
v8 = XKeysymToKeycode(display, v7);
v9 = XStringToKeysym("3");
v10 = XKeysymToKeycode(display, v9);
v11 = XStringToKeysym("4");
v12 = XKeysymToKeycode(display, v11);
osd_init();
if ( (unsigned int)get_xdevice(v4) )
{
puts("Spamming: Off - Use F12 to toggle.");
while ( 1 )
{
get_toggle();
nanosleep(&key_delay_0, 0LL);
if ( (unsigned int)get_key_state(v6) )
send_key(v6);
if ( (unsigned int)get_key_state(v8) )
send_key(v8);
if ( (unsigned int)get_key_state(v10) )
send_key(v10);
if ( (unsigned int)get_key_state(v12) )
send_key(v12);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
KeyCode v3; // al
char *v4; // r14
KeySym v5; // rax
unsigned int v6; // er13
KeySym v7; // rax
unsigned int v8; // er12
KeySym v9; // rax
unsigned int v10; // ebp
KeySym v11; // rax
unsigned int v12; // ebx
char *v14; // rax

display = XOpenDisplay(0LL);
if ( !display )
{
v14 = XDisplayName(0LL);
printf("Cannot connect to X server %s\n", v14);
exit(-1);
}
if ( argc <= 1 )
{
fprintf(stderr, "Usage: %s %s \n", *argv, "<KeyboardName>");
exit(-1);
}
v3 = XKeysymToKeycode(display, 0xFFC9uLL);
XGrabKey(display, v3, 0x8000u, display->screens[(__int64)display->default_screen].root, 0, 1, 1);
v4 = (char *)argv[1];
v5 = XStringToKeysym("1");
v6 = XKeysymToKeycode(display, v5);
v7 = XStringToKeysym("2");
v8 = XKeysymToKeycode(display, v7);
v9 = XStringToKeysym("3");
v10 = XKeysymToKeycode(display, v9);
v11 = XStringToKeysym("4");
v12 = XKeysymToKeycode(display, v11);
func11();
if ( (unsigned int)func7(v4) )
{
puts("Spamming: Off - Use F12 to toggle.");
while ( 1 )
{
func13();
nanosleep(&key_delay_0, 0LL);
if ( (unsigned int)func8(v6) )
func9(v6);
if ( (unsigned int)func8(v8) )
func9(v8);
if ( (unsigned int)func8(v10) )
func9(v10);
if ( (unsigned int)func8(v12) )
func9(v12);
}
}
return 0;
}

original_code:
int main (int argc, char *argv[])
{
  char *display_name = ((void *)0);
  if ((display = XOpenDisplay (display_name)) == ((void *)0))
    {
      printf ("Cannot connect to X server %s\n", XDisplayName (display_name));
      exit (-1);
    }
  if (argc < 2)
    {
      fprintf(stderr, "Usage: %s %s \n", argv[0], "<KeyboardName>");
      exit (-1);
    }
  int keycode = XKeysymToKeycode(display, 0xffc9);
  Window grab_window = ((&((_XPrivDisplay)(display))->screens[(((_XPrivDisplay)(display))->default_screen)])->root);
  XGrabKey(display,keycode,(1<<15),grab_window,0,1,1);
  char* name = argv[1];
  int keycode_1 = XKeysymToKeycode(display, XStringToKeysym("1"));
  int keycode_2 = XKeysymToKeycode(display, XStringToKeysym("2"));
  int keycode_3 = XKeysymToKeycode(display, XStringToKeysym("3"));
  int keycode_4 = XKeysymToKeycode(display, XStringToKeysym("4"));
  static struct timespec key_delay = { 0, (1000000000/50) };
  osd_init();
  if (get_xdevice(name))
    {
   printf("Spamming: Off - Use F12 to toggle.\n");
      while(1)
        {
          get_toggle();
          nanosleep(&key_delay,((void *)0));
          if (get_key_state(keycode_1)) {
            send_key(keycode_1);
          }
          if (get_key_state(keycode_2)) {
            send_key(keycode_2);
          }
          if (get_key_state(keycode_3)) {
   send_key(keycode_3);
          }
          if (get_key_state(keycode_4)) {
   send_key(keycode_4);
          }
        }
    }
  return(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char *display_name = ((void *)0);
  if ((display = XOpenDisplay (display_name)) == ((void *)0))
    {
      printf ("Cannot connect to X server %s\n", XDisplayName (display_name));
      exit (-1);
    }
  if (argc < 2)
    {
      fprintf(stderr, "Usage: %s %s \n", argv[0], "<KeyboardName>");
      exit (-1);
    }
  int keycode = XKeysymToKeycode(display, 0xffc9);
  unsigned long grab_window = ((&((_XPrivDisplay)(display))->screens[(((_XPrivDisplay)(display))->default_screen)])->root);
  XGrabKey(display,keycode,(1<<15),grab_window,0,1,1);
  char *name = argv[1];
  int keycode_1 = XKeysymToKeycode(display, XStringToKeysym("1"));
  int keycode_2 = XKeysymToKeycode(display, XStringToKeysym("2"));
  int keycode_3 = XKeysymToKeycode(display, XStringToKeysym("3"));
  int keycode_4 = XKeysymToKeycode(display, XStringToKeysym("4"));
  static struct timespec key_delay = { 0, (1000000000/50) };
  osd_init();
  if (get_xdevice(name))
    {
   printf("Spamming: Off - Use F12 to toggle.\n");
      while(1)
        {
          get_toggle();
          nanosleep(&key_delay,((void *)0));
          if (get_key_state(keycode_1)) {
            send_key(keycode_1);
          }
          if (get_key_state(keycode_2)) {
            send_key(keycode_2);
          }
          if (get_key_state(keycode_3)) {
   send_key(keycode_3);
          }
          if (get_key_state(keycode_4)) {
   send_key(keycode_4);
          }
        }
    }
  return(0);
}

variable_types: keycode int

variable_types:
name
char *

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
__int64 __fastcall get_xdevice(char *s2)
{
XListInputDevices();
fprintf(stderr, "Could not find the requested keyboard: %s\n", s2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s2)
{
XListInputDevices();
fprintf(stderr, "Could not find the requested keyboard: %s\n", s2);
return 0LL;
}

original_code:
int get_xdevice (char* name)
{
  XDeviceInfo *devs;
  int num_devs=0;
  int i=0;
  devs = XListInputDevices (display, &num_devs);
  for (i=0; i<num_devs; i++)
    {
      printf ("XID %d, type %2d, name \"%s\"\n",
              (int) devs[i].id, (int) devs[i].type, devs[i].name);
      if ((strncasecmp(devs[i].name, name, strlen(name)) == 0) &&
    ((devs[i].use == 1) || (devs[i].use == 3)))
        {
          printf("Opening XID %d \"%s\"\n", (int) devs[i].id, devs[i].name);
    xdevice = XOpenDevice(display, devs[i].id);
    free(devs);
    return 1;
        }
    }
  fprintf(stderr, "Could not find the requested keyboard: %s\n", name);
  return 0;
}

canonical_original_code:
int get_xdevice(char *name)
{
  struct _XDeviceInfo *devs;
  int num_devs = 0;
  int i = 0;
  devs = XListInputDevices (display, &num_devs);
  for (i=0; i<num_devs; i++)
    {
      printf ("XID %d, type %2d, name \"%s\"\n",
              (int) devs[i].id, (int) devs[i].type, devs[i].name);
      if ((strncasecmp(devs[i].name, name, strlen(name)) == 0) &&
    ((devs[i].use == 1) || (devs[i].use == 3)))
        {
          printf("Opening XID %d \"%s\"\n", (int) devs[i].id, devs[i].name);
    xdevice = XOpenDevice(display, devs[i].id);
    free(devs);
    return 1;
        }
    }
  fprintf(stderr, "Could not find the requested keyboard: %s\n", name);
  return 0;
}

variable_types: struct _XDeviceInfo { unsigned long id; unsigned long type; char *name; int num_classes; int use; struct _XAnyClassinfo { unsigned long class; int length; } *inputclassinfo; } *

variable_types: i int

user_defined_types: struct _XDeviceInfo { unsigned long id; unsigned long type; char *name; int num_classes; int use; struct _XAnyClassinfo *inputclassinfo; }


decompiled_code:
__int64 __fastcall get_key_state(int a1)
{
_QWORD *v1; // rax
unsigned int v2; // er12

v1 = (_QWORD *)XQueryDeviceState();
v2 = ((1 << (a1 % 8)) & *(char *)(v1[2] + a1 / 8 + 4LL)) >> (a1 % 8);
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
_QWORD *v1; // rax
unsigned int v2; // er12

v1 = (_QWORD *)XQueryDeviceState();
v2 = ((1 << (a1 % 8)) & *(char *)(v1[2] + a1 / 8 + 4LL)) >> (a1 % 8);
free(v1);
return v2;
}

original_code:
int get_key_state (int keycode) {
  XDeviceState *devicestate = ((void *)0);
  int state = 1;
  int byte = keycode / 8;
  int bit = keycode % 8;
  state = state << bit;
  devicestate = XQueryDeviceState(display, xdevice);
  int retval = (((XKeyState *) (devicestate->data))->keys[byte] & state) >> bit;
  free (devicestate);
  return retval;
}

canonical_original_code:
int get_key_state(int keycode) {
  struct XDeviceState *devicestate = ((void *)0);
  int state = 1;
  int byte = keycode / 8;
  int bit = keycode % 8;
  state = state << bit;
  devicestate = XQueryDeviceState(display, xdevice);
  int retval = (((XKeyState *) (devicestate->data))->keys[byte] & state) >> bit;
  free (devicestate);
  return retval;
}

variable_types: struct XDeviceState { unsigned long device_id; int num_classes; struct XInputClass { unsigned char class; unsigned char length; } *data; } *

variable_types: state int

variable_types: byte int

variable_types: bit int

variable_types: retval int

user_defined_types: struct XDeviceState { unsigned long device_id; int num_classes; struct XInputClass *data; }


decompiled_code:
int send_key()
{
XTestFakeKeyEvent();
XTestFakeKeyEvent();
return XFlush(display);
}

canonical_decompiled_code:
int func9()
{
XTestFakeKeyEvent();
XTestFakeKeyEvent();
return XFlush(display);
}

original_code:
void send_key(int keycode) {
  XTestFakeKeyEvent(display, keycode, 1, 0);
  XTestFakeKeyEvent(display, keycode, 0, 0);
  XFlush(display);
}


decompiled_code:
int send_button()
{
XTestFakeButtonEvent();
XTestFakeButtonEvent();
return XFlush(display);
}

canonical_decompiled_code:
int func10()
{
XTestFakeButtonEvent();
XTestFakeButtonEvent();
return XFlush(display);
}

original_code:
void send_button(int button) {
  XTestFakeButtonEvent(display, button,1 ,0);
  XTestFakeButtonEvent(display, button,0,0);
  XFlush(display);
}

variable_types: button int