main

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

gtk_init(0LL, 0LL, envp);
v3 = gtk_window_new(0LL);
v4 = gtk_widget_get_type();
v5 = g_type_check_instance_cast(v3, v4);
gtk_widget_set_size_request(v5, 600LL, 350LL);
v6 = gtk_window_get_type();
v7 = g_type_check_instance_cast(v3, v6);
gtk_window_set_title(v7, "Frontdown GTK UI");
v8 = gtk_container_get_type();
v9 = g_type_check_instance_cast(v3, v8);
gtk_container_set_border_width(v9, 10LL);
g_signal_connect_data(v3, "destroy", &gtk_main_quit, 0LL, 0LL, 0LL);
v10 = gtk_vbox_new(0LL, 0LL);
v11 = g_type_check_instance_cast(v3, v8);
gtk_container_add(v11, v10);
v12 = FrontDownFrame();
v13 = g_type_check_instance_cast(v10, v8);
gtk_container_add(v13, v12);
gtk_widget_show_all(v3);
gtk_main();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rax
__int64 v10; // r12
__int64 v11; // rdi
__int64 v12; // r13
__int64 v13; // rax

gtk_init(0LL, 0LL, envp);
v3 = gtk_window_new(0LL);
v4 = gtk_widget_get_type();
v5 = g_type_check_instance_cast(v3, v4);
gtk_widget_set_size_request(v5, 600LL, 350LL);
v6 = gtk_window_get_type();
v7 = g_type_check_instance_cast(v3, v6);
gtk_window_set_title(v7, "Frontdown GTK UI");
v8 = gtk_container_get_type();
v9 = g_type_check_instance_cast(v3, v8);
gtk_container_set_border_width(v9, 10LL);
g_signal_connect_data(v3, "destroy", &gtk_main_quit, 0LL, 0LL, 0LL);
v10 = gtk_vbox_new(0LL, 0LL);
v11 = g_type_check_instance_cast(v3, v8);
gtk_container_add(v11, v10);
v12 = func0();
v13 = g_type_check_instance_cast(v10, v8);
gtk_container_add(v13, v12);
gtk_widget_show_all(v3);
gtk_main();
return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 if((config.excludes = calloc(1, sizeof(struct frontdown_exclude_list)))==((void *)0)){
  fprintf(stderr,"Make sure you have enough memory and run it again");
  exit(1);
 }
 config.now=(long long)time(((void *)0));
 latest_exclude = config.excludes;
 config.source=malloc(16384);
 config.destination=malloc(16384);
 config.destinationUname=((void *)0);
 config.destinationPwd=((void *)0);
 config.info=&info;
 config.error=&error;
 config.source[0]=0;
 config.destination[0]=0;
 config.last_backup=0;
 config.verbose=0;
 if(parse_options(argc, argv)<0){
  fprintf(stderr,"\nRun '%s --help' for help\n", argv[0]);
  exit(64);
 }
 char urlbuffer[16384];
 if(strstr(config.destination, "file://") == config.destination) config.con_type=_FILE_;
 else if(strstr(config.destination, "ftp://") == config.destination) config.con_type=_FTP_;
 else if(strstr(config.destination, "sftp://") == config.destination) config.con_type=_SFTP_;
 else if(strstr(config.destination, "ftps://") == config.destination) config.con_type=_FTP_;
 else {
  config.con_type=_FILE_;
  strcpy(urlbuffer, "file://");
  strncat(urlbuffer, config.destination, 16384 -8);
  strcpy(config.destination, urlbuffer);
 }
 printf("================================ CONFIG ================================\n");
 printf("Configuration File:     %s\n", strlen(conf)==0?"None":conf);
 printf("Source:                 %s\n", config.source);
 printf("Destination:            %s\n", config.destination);
 printf("Backuped before:        %s\n", config.last_backup!=0?"yes":"no");
 printf("Verbose output:         %s\n", config.verbose!=0?"yes":"no");
 printf("========================================================================\n\n");
 char *buf;
 if(destinationLogin){
  config.destinationUname=getpass("User: ");
  buf=malloc(strlen(config.destinationUname));
  strcpy(buf, config.destinationUname);
  config.destinationUname=buf;
  config.destinationPwd=getpass("Password: ");
  buf=malloc(strlen(config.destinationPwd));
  strcpy(buf, config.destinationPwd);
  config.destinationPwd=buf;
  printf("\n\n");
 }
 frontdown(&config);
 return 0;
}

variable_types:
urlbuffer
char [16384]

variable_types:
buf
char *


usage

repo: percyfal/ngstk

decompiled_code:
__int64 usage()
{
fputc(10, stderr);
fwrite("Program: ngstk (C library toolkit for next-generation sequencing)\n", 1uLL, 0x42uLL, stderr);
fprintf(stderr, "Version: %s\n", "0.1.0");
fwrite("Contact: Per Unneberg <punneberg@gmail.com>\n\n", 1uLL, 0x2DuLL, stderr);
fwrite("Usage: ngstk <command> [options]\n\n", 1uLL, 0x24uLL, stderr);
fwrite("Command: angsd Parse output from angsd\n", 1uLL, 0x2CuLL, stderr);
fputc(10, stderr);
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
fputc(10, stderr);
fwrite("Program: ngstk (C library toolkit for next-generation sequencing)\n", 1uLL, 0x42uLL, stderr);
fprintf(stderr, "Version: %s\n", "0.1.0");
fwrite("Contact: Per Unneberg <punneberg@gmail.com>\n\n", 1uLL, 0x2DuLL, stderr);
fwrite("Usage: ngstk <command> [options]\n\n", 1uLL, 0x24uLL, stderr);
fwrite("Command: angsd Parse output from angsd\n", 1uLL, 0x2CuLL, stderr);
fputc(10, stderr);
return 1LL;
}

original_code:
static int usage()
{
 fprintf(stderr, "\n");
 fprintf(stderr, "Program: ngstk (C library toolkit for next-generation sequencing)\n");
 fprintf(stderr, "Version: %s\n", "0.1.0");
 fprintf(stderr, "Contact: Per Unneberg <punneberg@gmail.com>\n\n");
 fprintf(stderr, "Usage:   ngstk <command> [options]\n\n");
 fprintf(stderr, "Command: angsd      Parse output from angsd\n");
 fprintf(stderr, "\n");
 return 1;
}

return_type: int


main

canonical_name: main

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

if ( argc <= 1 )
return usage(argc, argv, envp);
v3 = argv[1];
if ( !strcmp(v3, "angsd") )
return angsd((unsigned int)(argc - 1), argv + 1);
fprintf(stderr, "[main] unrecognized command '%s'\n", v3);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r8

if ( argc <= 1 )
return func0(argc, argv, envp);
v3 = argv[1];
if ( !strcmp(v3, "angsd") )
return angsd((unsigned int)(argc - 1), argv + 1);
fprintf(stderr, "[main] unrecognized command '%s'\n", v3);
return 1;
}

original_code:
int main(int argc, char *argv[])
{
 if (argc < 2) return usage();
 if (strcmp(argv[1], "angsd") == 0) return angsd(argc-1, argv+1);
 else {
  fprintf(stderr, "[main] unrecognized command '%s'\n", argv[1]);
  return 1;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


ord

decompiled_code:
__int64 __fastcall ord(const void *a1, const void *a2)
{
return 2 * (unsigned int)(*(_DWORD *)a1 > *(_DWORD *)a2) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, const void *a2)
{
return 2 * (unsigned int)(*(_DWORD *)a1 > *(_DWORD *)a2) - 1;
}

original_code:
int ord(const void* a, const void* b){
  if(*(int*)a > *(int*)b) return 1;
  return -1;
}

canonical_original_code:
int ord(void *a, void *b){
  if(*(int *)a > *(int *)b) return 1;
  return -1;
}

variable_types:
a
void *

variable_types:
b
void *


rev

decompiled_code:
__int64 __fastcall rev(const void *a1, const void *a2)
{
return 2 * (unsigned int)(*(_DWORD *)a1 < *(_DWORD *)a2) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func8(const void *a1, const void *a2)
{
return 2 * (unsigned int)(*(_DWORD *)a1 < *(_DWORD *)a2) - 1;
}

original_code:
int rev(const void* a, const void* b){
  if(*(int*)a < *(int*)b) return 1;
  return -1;
}

canonical_original_code:
int rev(void *a, void *b){
  if(*(int *)a < *(int *)b) return 1;
  return -1;
}


quickV

decompiled_code:
__int64 __fastcall quickV(char *a1, int a2)
{
char *v2; // r13
int v3; // edx
char *v4; // rax
__int64 result; // rax

if ( a2 > 1 )
{
v2 = &a1[4 * (a2 / 2)];
v3 = *(_DWORD *)v2;
v4 = &a1[4 * a2 - 4];
*(_DWORD *)v2 = *(_DWORD *)v4;
*(_DWORD *)v4 = v3;
qsort(a1, a2 - 1, 4uLL, (__compar_fn_t)ord);
quickV(a1, (unsigned int)(a2 / 2));
result = quickV(v2, (unsigned int)(a2 - a2 / 2 - 1));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1, int a2)
{
char *v2; // r13
int v3; // edx
char *v4; // rax
__int64 result; // rax

if ( a2 > 1 )
{
v2 = &a1[4 * (a2 / 2)];
v3 = *(_DWORD *)v2;
v4 = &a1[4 * a2 - 4];
*(_DWORD *)v2 = *(_DWORD *)v4;
*(_DWORD *)v4 = v3;
qsort(a1, a2 - 1, 4uLL, (__compar_fn_t)ord);
func9(a1, (unsigned int)(a2 / 2));
result = func9(v2, (unsigned int)(a2 - a2 / 2 - 1));
}
return result;
}

original_code:
int quickV(int* a, int n){
  int half = n/2;
  int buffer;
  int i;
  if( n > 1 ) {
    do{ (buffer)=(a[half]); (a[half])=(a[n-1]); (a[n-1])=(buffer); }while(0);
    qsort(a,n-1,sizeof(int),ord);
    quickV(a, half);
    quickV(a+half, n-half-1);
  }
}

canonical_original_code:
int quickV(int *a, int n){
  int half = n/2;
  int buffer;
  int i;
  if( n > 1 ) {
    do{ (buffer)=(a[half]); (a[half])=(a[n-1]); (a[n-1])=(buffer); }while(0);
    qsort(a,n-1,sizeof(int),ord);
    quickV(a, half);
    quickV(a+half, n-half-1);
  }
}

variable_types:
a
int *

variable_types: n int

variable_types: half int

variable_types: buffer int

variable_types: i int


ale

decompiled_code:
__int64 ale()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
return 0LL;
}

original_code:
int ale(const void* a, const void* b){
  return 0;
}

canonical_original_code:
int ale(void *a, void *b){
  return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int *v4; // rbp
unsigned int v5; // eax
int v6; // er12
int *v7; // rbx
int v8; // edi
int *v9; // rax
__int64 v10; // rbx
int *v12; // rax
int *v13; // rdx
int v14; // edi
int *v15; // rsi
int *v16; // rcx
__int64 v17; // rdx
__int64 v18; // r15
int v19; // edi
int v20; // edi
char v21; // [rsp+Fh] [rbp-39h]

if ( argc != 3 )
{
fwrite(
"Uso: ./numgen tamanho tipo\n"
"\t a: aleatorio\n"
"\t o: ordenado\n"
"\t r: ordenado reverso\n"
"\t i: iguais\n"
"\t t: alternado\n"
"\t m: alternado para merge(pior caso)\n"
"\n",
1uLL,
0x8FuLL,
stderr);
exit(-1);
}
v3 = atoi(argv[1]);
v21 = *argv[2];
v4 = (int *)malloc(4LL * v3);
v5 = time(0LL);
srand(v5);
v6 = 10000;
if ( v3 >= 10000 )
v6 = v3;
if ( v3 > 0 )
{
v7 = v4;
do
*v7++ = rand() % v6;
while ( v7 != &v4[v3 - 1 + 1] );
switch ( v21 )
{
case 'a':
goto LABEL_17;
case 'i':
goto LABEL_11;
case 'm':
goto LABEL_9;
case 'o':
goto LABEL_15;
case 'r':
goto LABEL_20;
case 't':
goto LABEL_21;
default:
goto LABEL_27;
}
}
switch ( v21 )
{
case 'a':
goto LABEL_19;
case 'i':
LABEL_11:
if ( v3 <= 1 )
goto LABEL_16;
v9 = v4 + 1;
do
*v9++ = *v4;
while ( v9 != &v4[v3 - 2 + 2] );
goto LABEL_17;
case 'm':
LABEL_9:
v8 = 1;
if ( v3 <= 1 )
goto LABEL_16;
do
{
if ( v8 > 0 )
{
v12 = v4;
v13 = &v4[v8];
do
{
*v13 = *v12 + 1;
*v12 *= 2;
*v13 *= 2;
++v12;
++v13;
}
while ( v12 != &v4[v8 - 1 + 1] );
}
v8 *= 2;
}
while ( v3 > v8 );
v14 = v3 / 2;
if ( v3 > 3 )
{
v15 = &v4[v14];
v16 = v15;
v17 = 0LL;
v18 = v3 - (__int64)v14;
do
{
v19 = v4[v17];
v4[v17] = *(v16 - 1);
*(v16 - 1) = v19;
v20 = v15[v17];
v15[v17] = v16[v18 - 1];
v16[v18 - 1] = v20;
++v17;
--v16;
}
while ( v3 / 4 > (int)v17 );
}
goto LABEL_17;
case 'o':
LABEL_15:
qsort(v4, v3, 4uLL, (__compar_fn_t)ord);
goto LABEL_16;
case 'r':
LABEL_20:
qsort(v4, v3, 4uLL, (__compar_fn_t)rev);
goto LABEL_16;
case 't':
LABEL_21:
qsort(v4, v3, 4uLL, (__compar_fn_t)ord);
quickV((char *)v4, v3);
goto LABEL_16;
default:
LABEL_27:
puts("ERRO!!!");
LABEL_16:
if ( v3 > 0 )
{
LABEL_17:
v10 = 0LL;
do
printf(", %d", (unsigned int)v4[v10++]);
while ( v3 > (int)v10 );
}
LABEL_19:
free(v4);
free(0LL);
putchar(10);
return 0;
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int *v4; // rbp
unsigned int v5; // eax
int v6; // er12
int *v7; // rbx
int v8; // edi
int *v9; // rax
__int64 v10; // rbx
int *v12; // rax
int *v13; // rdx
int v14; // edi
int *v15; // rsi
int *v16; // rcx
__int64 v17; // rdx
__int64 v18; // r15
int v19; // edi
int v20; // edi
char v21; // [rsp+Fh] [rbp-39h]

if ( argc != 3 )
{
fwrite(
"Uso: ./numgen tamanho tipo\n"
"\t a: aleatorio\n"
"\t o: ordenado\n"
"\t r: ordenado reverso\n"
"\t i: iguais\n"
"\t t: alternado\n"
"\t m: alternado para merge(pior caso)\n"
"\n",
1uLL,
0x8FuLL,
stderr);
exit(-1);
}
v3 = atoi(argv[1]);
v21 = *argv[2];
v4 = (int *)malloc(4LL * v3);
v5 = time(0LL);
srand(v5);
v6 = 10000;
if ( v3 >= 10000 )
v6 = v3;
if ( v3 > 0 )
{
v7 = v4;
do
*v7++ = rand() % v6;
while ( v7 != &v4[v3 - 1 + 1] );
switch ( v21 )
{
case 'a':
goto LABEL_17;
case 'i':
goto LABEL_11;
case 'm':
goto LABEL_9;
case 'o':
goto LABEL_15;
case 'r':
goto LABEL_20;
case 't':
goto LABEL_21;
default:
goto LABEL_27;
}
}
switch ( v21 )
{
case 'a':
goto LABEL_19;
case 'i':
LABEL_11:
if ( v3 <= 1 )
goto LABEL_16;
v9 = v4 + 1;
do
*v9++ = *v4;
while ( v9 != &v4[v3 - 2 + 2] );
goto LABEL_17;
case 'm':
LABEL_9:
v8 = 1;
if ( v3 <= 1 )
goto LABEL_16;
do
{
if ( v8 > 0 )
{
v12 = v4;
v13 = &v4[v8];
do
{
*v13 = *v12 + 1;
*v12 *= 2;
*v13 *= 2;
++v12;
++v13;
}
while ( v12 != &v4[v8 - 1 + 1] );
}
v8 *= 2;
}
while ( v3 > v8 );
v14 = v3 / 2;
if ( v3 > 3 )
{
v15 = &v4[v14];
v16 = v15;
v17 = 0LL;
v18 = v3 - (__int64)v14;
do
{
v19 = v4[v17];
v4[v17] = *(v16 - 1);
*(v16 - 1) = v19;
v20 = v15[v17];
v15[v17] = v16[v18 - 1];
v16[v18 - 1] = v20;
++v17;
--v16;
}
while ( v3 / 4 > (int)v17 );
}
goto LABEL_17;
case 'o':
LABEL_15:
qsort(v4, v3, 4uLL, (__compar_fn_t)ord);
goto LABEL_16;
case 'r':
LABEL_20:
qsort(v4, v3, 4uLL, (__compar_fn_t)rev);
goto LABEL_16;
case 't':
LABEL_21:
qsort(v4, v3, 4uLL, (__compar_fn_t)ord);
func9((char *)v4, v3);
goto LABEL_16;
default:
LABEL_27:
puts("ERRO!!!");
LABEL_16:
if ( v3 > 0 )
{
LABEL_17:
v10 = 0LL;
do
printf(", %d", (unsigned int)v4[v10++]);
while ( v3 > (int)v10 );
}
LABEL_19:
free(v4);
free(0LL);
putchar(10);
return 0;
}
}

original_code:
int main(int argc, char* argv[] ) {
  int size, i;
  char opt;
  int *v, *v2;
  int max;
  int half, buffer;
  int t = 1;
  if(argc != 3 ){
    fprintf(stderr, "Uso: ./numgen tamanho tipo\n\t a: aleatorio\n\t o: ordenado\n\t r: ordenado reverso\n\t i: iguais\n\t t: alternado\n\t m: alternado para merge(pior caso)\n\n");
    exit(-1);
  }
  size = atoi(argv[1]);
  opt = argv[2][0];
  v = (int*)malloc(sizeof(int)*size);
  srand(time(0));
  max = size>10000? size:10000;
  for(i=0; i<size; i++){
    v[i] = rand()%max;
  }
  switch(opt){
  case 'a':
    break;
  case 'o':
    qsort(v,size,sizeof(int),ord);
    break;
  case 'r':
    qsort(v,size,sizeof(int),rev);
    break;
  case 'i':
    for(i=1; i<size; i++){
      v[i] = v[0];
    }
    break;
  case 't':
    qsort(v,size,sizeof(int),ord);
    quickV(v,size);
    break;
  case 'm':
    while(t<size){
      for(i=0; i<t; i++){
 v[t+i] = v[i] + 1;
 v[i]*=2;
 v[t+i]*=2;
      }
      t*=2;
    }
    half = size/2;
    for(i=0; i<half/2; i++){
      do{ (buffer)=(v[i]); (v[i])=(v[half-i-1]); (v[half-i-1])=(buffer); }while(0);
      do{ (buffer)=(v[i+half]); (v[i+half])=(v[size-i-1]); (v[size-i-1])=(buffer); }while(0);
    }
    break;
  default:
    puts("ERRO!!!");
  }
  for(i=0; i<size; i++){
    printf(", %d", v[i]);
  }
  free(v);
  free(v2);
  printf("\n");
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int size; int i;
  char opt;
  int *v; int *v2;
  int max;
  int half; int buffer;
  int t = 1;
  if(argc != 3 ){
    fprintf(stderr, "Uso: ./numgen tamanho tipo\n\t a: aleatorio\n\t o: ordenado\n\t r: ordenado reverso\n\t i: iguais\n\t t: alternado\n\t m: alternado para merge(pior caso)\n\n");
    exit(-1);
  }
  size = atoi(argv[1]);
  opt = argv[2][0];
  v = (int *)malloc(sizeof(int)*size);
  srand(time(0));
  max = size>10000? size:10000;
  for(i=0; i<size; i++){
    v[i] = rand()%max;
  }
  switch(opt){
  case 'a':
    break;
  case 'o':
    qsort(v,size,sizeof(int),ord);
    break;
  case 'r':
    qsort(v,size,sizeof(int),rev);
    break;
  case 'i':
    for(i=1; i<size; i++){
      v[i] = v[0];
    }
    break;
  case 't':
    qsort(v,size,sizeof(int),ord);
    quickV(v,size);
    break;
  case 'm':
    while(t<size){
      for(i=0; i<t; i++){
 v[t+i] = v[i] + 1;
 v[i]*=2;
 v[t+i]*=2;
      }
      t*=2;
    }
    half = size/2;
    for(i=0; i<half/2; i++){
      do{ (buffer)=(v[i]); (v[i])=(v[half-i-1]); (v[half-i-1])=(buffer); }while(0);
      do{ (buffer)=(v[i+half]); (v[i+half])=(v[size-i-1]); (v[size-i-1])=(buffer); }while(0);
    }
    break;
  default:
    puts("ERRO!!!");
  }
  for(i=0; i<size; i++){
    printf(", %d", v[i]);
  }
  free(v);
  free(v2);
  printf("\n");
}

variable_types: size int

variable_types: opt char

variable_types:
v
int *

variable_types: max int

variable_types: t int


mergeS

original_code:
void mergeS(int *a, int n) {
    int i, j, k, half;
    half = n/2;
    int *temp = (int*)malloc(sizeof(int)*n);
    if (!temp) exit(1);
    i = 0;
    j = half;
    k = 0;
    while (i < half && j < n) {
        if (a[i] > a[j]) {
            temp[k] = a[j];
            ++j;
        } else {
            temp[k] = a[i];
            ++i;
        }
        ++k;
    }
        if ( i == half) {
            while(j < n) {
                temp[k] = a[j];
                ++k;
                ++j;
            }
        }
            else {
                    while (i < half) {
                    temp[k] = a[i];
                    ++k;
                    ++i;
                }
            }
        for (i = 0; i < n; ++i) a[i] = temp[i];
        free(temp);
}

canonical_original_code:
void mergeS(int *a, int n) {
    int i; int j; int k; int half;
    half = n/2;
    int *temp = (int*)malloc(sizeof(int)*n);
    if (!temp) exit(1);
    i = 0;
    j = half;
    k = 0;
    while (i < half && j < n) {
        if (a[i] > a[j]) {
            temp[k] = a[j];
            ++j;
        } else {
            temp[k] = a[i];
            ++i;
        }
        ++k;
    }
        if ( i == half) {
            while(j < n) {
                temp[k] = a[j];
                ++k;
                ++j;
            }
        }
            else {
                    while (i < half) {
                    temp[k] = a[i];
                    ++k;
                    ++i;
                }
            }
        for (i = 0; i < n; ++i) a[i] = temp[i];
        free(temp);
}

variable_types: j int

variable_types: k int

variable_types:
temp
int *

return_type: void


mergeSort

decompiled_code:
void __fastcall mergeSort(__int64 a1, int a2)
{
if ( a2 > 1 )
{
mergeSort(a1, (unsigned int)(a2 / 2));
mergeSort(a1 + 4LL * (a2 / 2), (unsigned int)(a2 - a2 / 2));
mergeS(a1, a2);
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2)
{
if ( a2 > 1 )
{
func8(a1, (unsigned int)(a2 / 2));
func8(a1 + 4LL * (a2 / 2), (unsigned int)(a2 - a2 / 2));
func7(a1, a2);
}
}

original_code:
void mergeSort(int *a, int n) {
    if (n > 1) {
        int half = n/2;
        mergeSort(a,half);
        mergeSort(a + half, n - half);
        mergeS(a,n);
    }
}


read

decompiled_code:
__int64 __fastcall read(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( a2 > 0 )
{
v2 = a1;
do
{
result = __isoc99_scanf();
v2 += 4LL;
}
while ( v2 != a1 + 4LL * (unsigned int)(a2 - 1) + 4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( a2 > 0 )
{
v2 = a1;
do
{
result = __isoc99_scanf();
v2 += 4LL;
}
while ( v2 != a1 + 4LL * (unsigned int)(a2 - 1) + 4 );
}
return result;
}

original_code:
void read(int *a, int n) {
  int i;
  for(i = 0; i < n; i++)
    scanf(", %d",&a[i]);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbx
_DWORD *v4; // rax
_DWORD *v5; // rbp
int v6; // er12
__int64 v7; // rax
int v9; // [rsp+Ch] [rbp-1Ch]

__isoc99_scanf();
v3 = malloc(4LL * v9);
v4 = malloc(4LL * v9);
if ( !v3 || (v5 = v4) == 0LL )
{
puts("Malloc falhou!");
exit(1);
}
read((__int64)v4, v9);
v6 = 5000;
do
{
v7 = 0LL;
if ( v9 > 0 )
{
do
{
v3[v7] = v5[v7];
++v7;
}
while ( v9 != v7 );
}
mergeSort((__int64)v3, v9);
--v6;
}
while ( v6 );
free(v5);
free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbx
_DWORD *v4; // rax
_DWORD *v5; // rbp
int v6; // er12
__int64 v7; // rax
int v9; // [rsp+Ch] [rbp-1Ch]

__isoc99_scanf();
v3 = malloc(4LL * v9);
v4 = malloc(4LL * v9);
if ( !v3 || (v5 = v4) == 0LL )
{
puts("Malloc falhou!");
exit(1);
}
func9((__int64)v4, v9);
v6 = 5000;
do
{
v7 = 0LL;
if ( v9 > 0 )
{
do
{
v3[v7] = v5[v7];
++v7;
}
while ( v9 != v7 );
}
func8((__int64)v3, v9);
--v6;
}
while ( v6 );
free(v5);
free(v3);
return 0;
}

original_code:
int main(int argc, char **argv) {
  int n, i, j;
  scanf(" %d", &n);
  int *a = (int*)malloc(sizeof(int)*n);
  int *b = (int*)malloc(sizeof(int)*n);
  if (a == ((void *)0) || b == ((void *)0)){
    puts("Malloc falhou!");
    exit(1);
  }
  read(b,n);
  for(j=0; j<5000; j++){
    for(i=0; i<n; i++){
      a[i] = b[i];
    }
    mergeSort(a,n);
  }
  free(b);
  free(a);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int n; int i; int j;
  scanf(" %d", &n);
  int *a = (int*)malloc(sizeof(int)*n);
  int *b = (int*)malloc(sizeof(int)*n);
  if (a == ((void *)0) || b == ((void *)0)){
    puts("Malloc falhou!");
    exit(1);
  }
  read(b,n);
  for(j=0; j<5000; j++){
    for(i=0; i<n; i++){
      a[i] = b[i];
    }
    mergeSort(a,n);
  }
  free(b);
  free(a);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
b
int *


insertionSort

original_code:
void insertionSort(int *v, int size){
  int i, j, k, aux;
  for(i=1; i<size; i++){
    for(j=0; j<i; j++){
      if( v[i] < v[j] ){
 aux = v[i];
 for( k=i; k>j; k--){
   v[k] = v[k-1];
 }
 v[j] = aux;
 break;
      }
    }
  }
}

canonical_original_code:
void insertionSort(int *v, int size){
  int i; int j; int k; int aux;
  for(i=1; i<size; i++){
    for(j=0; j<i; j++){
      if( v[i] < v[j] ){
 aux = v[i];
 for( k=i; k>j; k--){
   v[k] = v[k-1];
 }
 v[j] = aux;
 break;
      }
    }
  }
}

variable_types: aux int


partit

variable_types:
a
int *

variable_types: l int

variable_types: r int

variable_types: pivot int

variable_types: left int

variable_types: right int


quickSort

decompiled_code:
void __fastcall quickSort(__int64 a1, int a2, signed int a3)
{
int v5; // esi
int v6; // er13

v5 = a3 - a2;
if ( v5 > 5 )
{
v6 = partit(a1, a2, a3);
quickSort(a1, (unsigned int)a2, (unsigned int)(v6 - 1));
quickSort(a1, (unsigned int)(v6 + 1), (unsigned int)a3);
}
else if ( a3 > a2 )
{
insertionSort((_DWORD *)(a1 + 4LL * a2), v5 + 1);
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2, signed int a3)
{
int v5; // esi
int v6; // er13

v5 = a3 - a2;
if ( v5 > 5 )
{
v6 = func7(a1, a2, a3);
func9(a1, (unsigned int)a2, (unsigned int)(v6 - 1));
func9(a1, (unsigned int)(v6 + 1), (unsigned int)a3);
}
else if ( a3 > a2 )
{
func8((_DWORD *)(a1 + 4LL * a2), v5 + 1);
}
}

original_code:
void quickSort(int *a, int l, int r) {
  int pivot;
  if ( (r-l) > 5) {
    pivot = partit(a,l,r);
    quickSort(a,l,pivot-1);
    quickSort(a,pivot+1,r);
  } else if (r > l) {
    insertionSort( (a+l), (r-l+1) );
  }
}


read

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( a2 > 0 )
{
v2 = a1;
do
{
result = __isoc99_scanf();
v2 += 4LL;
}
while ( v2 != a1 + 4LL * (unsigned int)(a2 - 1) + 4 );
}
return result;
}

original_code:
void read(int* a, int n) {
  int i;
  for(i = 0; i < n; i++)
    scanf(", %d",&a[i]);
}

canonical_original_code:
void read(int *a, int n) {
  int i;
  for(i = 0; i < n; i++)
    scanf(", %d",&a[i]);
}

variable_types: n int

variable_types: i int


prt

decompiled_code:
int __fastcall prt(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
printf("%d ", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return puts("");
}

canonical_decompiled_code:
int __fastcall func11(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
printf("%d ", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return puts("");
}

original_code:
void prt(int* a, int n) {
  int i;
  for(i = 0; i < n; i++)
    printf("%d ",a[i]);
  puts("");
}

canonical_original_code:
void prt(int *a, int n) {
  int i;
  for(i = 0; i < n; i++)
    printf("%d ",a[i]);
  puts("");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbx
_DWORD *v4; // rax
_DWORD *v5; // rbp
int v6; // er12
__int64 v7; // rax
int v9; // [rsp+Ch] [rbp-1Ch]

__isoc99_scanf();
v3 = malloc(4LL * v9);
v4 = malloc(4LL * v9);
if ( !v3 || (v5 = v4) == 0LL )
{
puts("Malloc falhou!");
exit(1);
}
read((__int64)v4, v9);
v6 = 5000;
do
{
v7 = 0LL;
if ( v9 > 0 )
{
do
{
v3[v7] = v5[v7];
++v7;
}
while ( v9 != v7 );
}
quickSort((__int64)v3, 0, v9 - 1);
--v6;
}
while ( v6 );
free(v3);
free(v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbx
_DWORD *v4; // rax
_DWORD *v5; // rbp
int v6; // er12
__int64 v7; // rax
int v9; // [rsp+Ch] [rbp-1Ch]

__isoc99_scanf();
v3 = malloc(4LL * v9);
v4 = malloc(4LL * v9);
if ( !v3 || (v5 = v4) == 0LL )
{
puts("Malloc falhou!");
exit(1);
}
func10((__int64)v4, v9);
v6 = 5000;
do
{
v7 = 0LL;
if ( v9 > 0 )
{
do
{
v3[v7] = v5[v7];
++v7;
}
while ( v9 != v7 );
}
func9((__int64)v3, 0, v9 - 1);
--v6;
}
while ( v6 );
free(v3);
free(v5);
return 0;
}

original_code:
int main(int argc, char **argv) {
  int n, i, j, *b, *a;
  scanf(" %d", &n);
  a = (int*)malloc(sizeof(int)*n);
  b = (int*)malloc(sizeof(int)*n);
  if (a == ((void *)0) || b == ((void *)0)){
    puts("Malloc falhou!");
    exit(1);
  }
  read(b,n);
  for(j=0; j<5000; j++){
    for(i=0; i<n; i++){
      a[i] = b[i];
    }
    quickSort(a,0,n-1);
  }
  free(a);
  free(b);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int n; int i; int j; int *b; int *a;
  scanf(" %d", &n);
  a = (int *)malloc(sizeof(int)*n);
  b = (int *)malloc(sizeof(int)*n);
  if (a == ((void *)0) || b == ((void *)0)){
    puts("Malloc falhou!");
    exit(1);
  }
  read(b,n);
  for(j=0; j<5000; j++){
    for(i=0; i<n; i++){
      a[i] = b[i];
    }
    quickSort(a,0,n-1);
  }
  free(a);
  free(b);
  return 0;
}


restore

original_code:
void restore(int v[], int root, int size){
  int sonL, sonR, buffer;
  int newr, maxi;
  do{
    if(root > size) return;
    sonL = (2*(root) + 1);
    sonR = (2*(root) + 2);
    if(sonL > size) return;
    if(sonR > size){
      if(v[sonL] < v[root]){
 return;
      }
      do{ (buffer)=(v[sonL]); (v[sonL])=(v[root]); (v[root])=(buffer); }while(0);
      newr = sonL;
    } else {
      maxi = ((v[sonL])>(v[sonR])?(sonL):(sonR));
      if(v[maxi] < v[root]) {
 return;
      }
      do{ (buffer)=(v[maxi]); (v[maxi])=(v[root]); (v[root])=(buffer); }while(0);
      newr=maxi;
    }
    root = newr;
  } while(1);
}

canonical_original_code:
void restore(int v[], int root, int size){
  int sonL; int sonR; int buffer;
  int newr; int maxi;
  do{
    if(root > size) return;
    sonL = (2*(root) + 1);
    sonR = (2*(root) + 2);
    if(sonL > size) return;
    if(sonR > size){
      if(v[sonL] < v[root]){
 return;
      }
      do{ (buffer)=(v[sonL]); (v[sonL])=(v[root]); (v[root])=(buffer); }while(0);
      newr = sonL;
    } else {
      maxi = ((v[sonL])>(v[sonR])?(sonL):(sonR));
      if(v[maxi] < v[root]) {
 return;
      }
      do{ (buffer)=(v[maxi]); (v[maxi])=(v[root]); (v[root])=(buffer); }while(0);
      newr=maxi;
    }
    root = newr;
  } while(1);
}

variable_types:
v
int []

variable_types: root int

variable_types: size int

variable_types: sonL int

variable_types: sonR int

variable_types: buffer int

variable_types: newr int

variable_types: maxi int


read

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( a2 > 0 )
{
v2 = a1;
do
{
result = __isoc99_scanf();
v2 += 4LL;
}
while ( v2 != a1 + 4LL * (unsigned int)(a2 - 1) + 4 );
}
return result;
}


main

original_code:
int main(int argc, char** argv){
  int i, j, k, buffer, father;
  int size;
  int* v, *v2;
  int M, sonR, sonL;
  scanf(" %d", &size);
  v = (int*)malloc(sizeof(int)*size);
  v2= (int*)malloc(sizeof(int)*size);
  read(v2,size);
  for(k=0; k<5000; k++){
    for(i=0; i<size; i++){
      v[i] = v2[i];
    }
    for(i=1; i<size; i++){
      j=i;
      father = (((i)-1)/2);
      while( v[father] < v[j]){
 do{ (buffer)=(v[father]); (v[father])=(v[j]); (v[j])=(buffer); }while(0);
 j = father;
 father = (((father)-1)/2);
      }
    }
    for(i=1; i<size; i++){
      do{ (buffer)=(v[0]); (v[0])=(v[size-i]); (v[size-i])=(buffer); }while(0);
      restore(v, 0, (size-i-1));
    }
  }
  free(v);
  free(v2);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
  int i; int j; int k; int buffer; int father;
  int size;
  int *v; int *v2;
  int M; int sonR; int sonL;
  scanf(" %d", &size);
  v = (int *)malloc(sizeof(int)*size);
  v2= (int *)malloc(sizeof(int)*size);
  read(v2,size);
  for(k=0; k<5000; k++){
    for(i=0; i<size; i++){
      v[i] = v2[i];
    }
    for(i=1; i<size; i++){
      j=i;
      father = (((i)-1)/2);
      while( v[father] < v[j]){
 do{ (buffer)=(v[father]); (v[father])=(v[j]); (v[j])=(buffer); }while(0);
 j = father;
 father = (((father)-1)/2);
      }
    }
    for(i=1; i<size; i++){
      do{ (buffer)=(v[0]); (v[0])=(v[size-i]); (v[size-i])=(buffer); }while(0);
      restore(v, 0, (size-i-1));
    }
  }
  free(v);
  free(v2);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: j int

variable_types: k int

variable_types: father int

variable_types:
v
int *

variable_types: M int


repo: perezdidac/portscan

decompiled_code:
void __noreturn ps_cancel()
{
size_t v0; // rax
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

strcpy(v1, "Killing childs...\n");
v0 = strlen(v1);
write(2, v1, v0);
kill(0, 2);
while ( waitpid(-1, 0LL, 1) > 0 )
;
exit(3);
}

canonical_decompiled_code:
void __noreturn func0()
{
size_t v0; // rax
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

strcpy(v1, "Killing childs...\n");
v0 = strlen(v1);
write(2, v1, v0);
kill(0, 2);
while ( waitpid(-1, 0LL, 1) > 0 )
;
exit(3);
}

original_code:
void ps_cancel( int sig )
{
   char str[255];
   sprintf( str, "Killing childs...\n" );
   write( 2, str, strlen( str ) );
   kill( 0, 2 );
   while (waitpid( -1, ((void *)0), 1) > 0) ;
   exit (PS_EXIT_STATUS_CANCEL);
}

canonical_original_code:
void ps_cancel(int sig)
{
   char str[255];
   sprintf( str, "Killing childs...\n" );
   write( 2, str, strlen( str ) );
   kill( 0, 2 );
   while (waitpid( -1, ((void *)0), 1) > 0) ;
   exit (PS_EXIT_STATUS_CANCEL);
}

variable_types: sig int

variable_types:
str
char [255]


decompiled_code:
void __noreturn ps_show_help()
{
puts(s);
puts(
"SYNOPSIS\n"
" portscan [OPTION]...\n"
"\n"
"DESCRIPTION\n"
" Scans a desired range of TCP/IP ports to a remote machine and shows the\n"
" results. The program can use multiple number of sub-processes working\n"
" together to optimize the time of application.\n"
"\n"
" -l log filename\n"
" -d remote hostname\n"
" -s initial port for start scanning\n"
" -e end port\n"
" -c max number of childs\n"
" -h display the usage of the program\n"
" -v output version information and exit\n"
"\n"
" By default, the program uses 8 childs at maximum. If -d option is not used,\n"
" portscan reads hostnames from the standard input.\n"
" Exit status:\n"
" 0 if OK,\n"
" 1 if nothing was done,\n"
" 2 if an error occour,\n"
" 3 if the application has been cancelled during the scan process\n");
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
puts(s);
puts(
"SYNOPSIS\n"
" portscan [OPTION]...\n"
"\n"
"DESCRIPTION\n"
" Scans a desired range of TCP/IP ports to a remote machine and shows the\n"
" results. The program can use multiple number of sub-processes working\n"
" together to optimize the time of application.\n"
"\n"
" -l log filename\n"
" -d remote hostname\n"
" -s initial port for start scanning\n"
" -e end port\n"
" -c max number of childs\n"
" -h display the usage of the program\n"
" -v output version information and exit\n"
"\n"
" By default, the program uses 8 childs at maximum. If -d option is not used,\n"
" portscan reads hostnames from the standard input.\n"
" Exit status:\n"
" 0 if OK,\n"
" 1 if nothing was done,\n"
" 2 if an error occour,\n"
" 3 if the application has been cancelled during the scan process\n");
exit(1);
}

original_code:
void ps_show_help()
{
   printf( "portscan version ""0.3"".\n" "Developed by ""D. Pérez and A. Hernández"".\n\n" );
   printf( "SYNOPSIS\n" "       portscan [OPTION]...\n\n" "DESCRIPTION\n" "       Scans  a  desired  range  of  TCP/IP  ports to a remote machine and shows the\n" "       results. The  program  can  use  multiple  number  of  sub-processes  working\n" "       together to optimize the time of application.\n\n" "       -l     log filename\n" "       -d     remote hostname\n" "       -s     initial port for start scanning\n" "       -e     end port\n" "       -c     max number of childs\n" "       -h     display the usage of the program\n" "       -v     output version information and exit\n\n" "       By  default, the program uses 8 childs at maximum.  If -d option is not used,\n" "       portscan reads hostnames from the standard input.\n" "   Exit status:\n" "       0      if OK,\n" "       1      if nothing was done,\n" "       2      if an error occour,\n" "       3      if the application has been cancelled during the scan process\n\n" );
   exit (PS_EXIT_STATUS_NOTHING);
}


decompiled_code:
void __noreturn ps_show_version()
{
puts(s);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
puts(s);
exit(1);
}

original_code:
void ps_show_version()
{
   printf( "portscan version ""0.3"".\n" "Developed by ""D. Pérez and A. Hernández"".\n\n" );
   exit (PS_EXIT_STATUS_NOTHING);
}


decompiled_code:
__int64 __fastcall ps_parse_options(int argc, char **argv, __int64 a3)
{
char *v4; // r13
int v5; // eax
__int64 result; // rax

*(_DWORD *)(a3 + 4) = -1;
*(_WORD *)(a3 + 272) = 8;
*(_WORD *)(a3 + 274) = 1;
*(_WORD *)(a3 + 276) = -1;
*(_WORD *)(a3 + 278) = 1000;
*(_DWORD *)a3 = -1;
v4 = (char *)(a3 + 16);
while ( 1 )
{
v5 = getopt(argc, argv, "l:c:t:d:s:e:hv");
if ( v5 == -1 )
return 0LL;
switch ( v5 )
{
case 'c':
*(_WORD *)(a3 + 272) = atoi(optarg);
break;
case 'd':
strcpy(v4, optarg);
*(_DWORD *)a3 = 0;
break;
case 'e':
*(_WORD *)(a3 + 276) = atoi(optarg);
break;
case 'h':
ps_show_help();
return result;
case 'l':
*(_QWORD *)(a3 + 8) = optarg;
*(_DWORD *)(a3 + 4) = 0;
break;
case 's':
*(_WORD *)(a3 + 274) = atoi(optarg);
break;
case 't':
*(_WORD *)(a3 + 278) = atoi(optarg);
break;
case 'v':
ps_show_version();
return result;
default:
continue;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func3(int argc, char **argv, __int64 a3)
{
char *v4; // r13
int v5; // eax
__int64 result; // rax

*(_DWORD *)(a3 + 4) = -1;
*(_WORD *)(a3 + 272) = 8;
*(_WORD *)(a3 + 274) = 1;
*(_WORD *)(a3 + 276) = -1;
*(_WORD *)(a3 + 278) = 1000;
*(_DWORD *)a3 = -1;
v4 = (char *)(a3 + 16);
while ( 1 )
{
v5 = getopt(argc, argv, "l:c:t:d:s:e:hv");
if ( v5 == -1 )
return 0LL;
switch ( v5 )
{
case 'c':
*(_WORD *)(a3 + 272) = atoi(optarg);
break;
case 'd':
strcpy(v4, optarg);
*(_DWORD *)a3 = 0;
break;
case 'e':
*(_WORD *)(a3 + 276) = atoi(optarg);
break;
case 'h':
func1();
return result;
case 'l':
*(_QWORD *)(a3 + 8) = optarg;
*(_DWORD *)(a3 + 4) = 0;
break;
case 's':
*(_WORD *)(a3 + 274) = atoi(optarg);
break;
case 't':
*(_WORD *)(a3 + 278) = atoi(optarg);
break;
case 'v':
func2();
return result;
default:
continue;
}
}
}

original_code:
int ps_parse_options( int argc, char *argv[], struct options_t *options )
{
   int ret;
   extern char *optarg;
   options->log = -1;
   options->maxchilds = 8;
   options->minport = 1;
   options->maxport = 65535;
   options->timeout = 1000;
   options->from_stdin = -1;
   while ((ret = getopt( argc, argv, "l:c:t:d:s:e:hv" )) != -1)
   {
      switch (ret)
      {
         case 'l':
            options->filename = optarg;
            options->log = 0;
            break;
         case 'c':
            options->maxchilds = atoi( optarg );
            break;
         case 't':
            options->timeout = atoi( optarg );
            break;
         case 'd':
            strcpy( options->ip, optarg );
            options->from_stdin = 0;
            break;
         case 's':
            options->minport = atoi( optarg );
            break;
         case 'e':
            options->maxport = atoi( optarg );
            break;
         case 'h':
            ps_show_help();
            exit (PS_EXIT_STATUS_NOTHING);
         case 'v':
            ps_show_version();
            exit (PS_EXIT_STATUS_NOTHING);
         default:
            break;
      }
   }
   return (0);
}

canonical_original_code:
int ps_parse_options(int argc, char *argv[], struct options_t *options)
{
   int ret;
   extern char *optarg;
   options->log = -1;
   options->maxchilds = 8;
   options->minport = 1;
   options->maxport = 65535;
   options->timeout = 1000;
   options->from_stdin = -1;
   while ((ret = getopt( argc, argv, "l:c:t:d:s:e:hv" )) != -1)
   {
      switch (ret)
      {
         case 'l':
            options->filename = optarg;
            options->log = 0;
            break;
         case 'c':
            options->maxchilds = atoi( optarg );
            break;
         case 't':
            options->timeout = atoi( optarg );
            break;
         case 'd':
            strcpy( options->ip, optarg );
            options->from_stdin = 0;
            break;
         case 's':
            options->minport = atoi( optarg );
            break;
         case 'e':
            options->maxport = atoi( optarg );
            break;
         case 'h':
            ps_show_help();
            exit (PS_EXIT_STATUS_NOTHING);
         case 'v':
            ps_show_version();
            exit (PS_EXIT_STATUS_NOTHING);
         default:
            break;
      }
   }
   return (0);
}

variable_types:
argv
char *[]

variable_types: struct options_t { int from_stdin; int log; char *filename; char ip[255]; unsigned short maxchilds; unsigned short minport; unsigned short maxport; unsigned short timeout; } *

variable_types: ret int

variable_types:
optarg
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
void *v4; // rsp
int k; // ebx
int i; // er12
int *v7; // rbx
__pid_t v8; // eax
int *v9; // rbx
__int64 v10; // r13
size_t v11; // rax
size_t v12; // rax
size_t v13; // rax
int v14; // ebx
int *v16; // rbx
int j; // ebx
unsigned __int16 v18; // bx
void *v19; // rsp
__int64 v20[2]; // [rsp+0h] [rbp-280h] BYREF
int fd; // [rsp+10h] [rbp-270h]
in_addr_t v22; // [rsp+14h] [rbp-26Ch]
int v23; // [rsp+18h] [rbp-268h]
unsigned __int16 v24; // [rsp+1Ch] [rbp-264h]
unsigned __int16 v25; // [rsp+1Eh] [rbp-262h]
unsigned int buf; // [rsp+28h] [rbp-258h] BYREF
unsigned __int16 v27; // [rsp+2Ch] [rbp-254h]
char s[256]; // [rsp+30h] [rbp-250h] BYREF
int v29; // [rsp+130h] [rbp-150h] BYREF
int v30; // [rsp+134h] [rbp-14Ch]
char *file; // [rsp+138h] [rbp-148h]
char cp[256]; // [rsp+140h] [rbp-140h] BYREF
unsigned __int16 v33; // [rsp+240h] [rbp-40h]
unsigned __int16 v34; // [rsp+242h] [rbp-3Eh]
unsigned __int16 v35; // [rsp+244h] [rbp-3Ch]
unsigned __int16 v36; // [rsp+246h] [rbp-3Ah]

ps_parse_options(argc, (char **)argv, (__int64)&v29);
if ( !v30 )
{
fd = open(file, 577);
if ( fd < 0 )
ps_error(0LL);
}
do
{
v20[1] = (__int64)v20;
if ( v29 == -1 && (unsigned int)_isoc99_scanf("%s", cp) == -1 )
break;
v22 = inet_addr(cp);
if ( v22 == -1 )
{
v22 = ps_getip(cp);
if ( v22 == -1 )
ps_error(3LL);
}
v25 = v34;
if ( !v34 )
ps_error(4LL);
v18 = v35;
if ( !v35 )
ps_error(5LL);
v24 = v36;
if ( !v36 )
ps_error(7LL);
if ( v25 > v18 )
ps_error(6LL);
if ( v33 )
{
v23 = v18 - v25;
v3 = v23 + 1;
if ( v23 + 1 > v33 )
v3 = v33;
v19 = alloca(8LL * v3);
v7 = (int *)v20;
v20[0] = (__int64)v20;
if ( v3 > 0 )
{
for ( i = 0; i != v3; ++i )
{
if ( pipe(v7) < 0 )
ps_error(8LL);
v8 = fork();
if ( v8 < 0 )
{
ps_error(9LL);
}
else if ( !v8 )
{
close(HIDWORD(v20[i]));
if ( i > 0 )
{
v9 = (int *)v20 + 1;
v10 = v20[0] + 8LL * (unsigned int)(i - 1) + 12;
do
{
close(*v9);
v9 += 2;
}
while ( v9 != (int *)v10 );
}
while ( read(v20[i], &buf, 8uLL) == 8 )
{
if ( !v30 )
{
sprintf(s, "Child %d started scanning...\n", (unsigned int)i);
v11 = strlen(s);
write(fd, s, v11);
}
v14 = ps_scan(buf, v27, v24);
if ( !v30 )
{
sprintf(s, "Child %d finished.\n", (unsigned int)i);
v12 = strlen(s);
write(fd, s, v12);
}
if ( v14 )
{
if ( v14 == 1 )
{
sprintf(s, "%s %d SUCCESS\n", cp, v27);
}
else if ( v14 == 2 )
{
sprintf(s, "%s %d TIMEOUT\n", cp, v27);
}
}
else
{
sprintf(s, "%s %d ERROR\n", cp, v27);
}
v13 = strlen(s);
write(1, s, v13);
}
close(v20[i]);
return 0;
}
close(*v7);
v7 += 2;
}
signal(2, (__sighandler_t)ps_cancel);
if ( v23 >= 0 )
goto LABEL_13;
LABEL_42:
v16 = (int *)v20 + 1;
do
{
close(*v16);
v16 += 2;
}
while ( v16 != (int *)((char *)&v20[(unsigned int)(v3 - 1) + 1] + 4) );
for ( j = 0; j != v3; ++j )
wait(0LL);
goto LABEL_46;
}
}
else
{
ps_error(2LL);
v23 = v18 - v25;
v3 = v23 + 1;
if ( v23 + 1 > 0 )
v3 = 0;
v4 = alloca(8LL * v3);
}
signal(2, (__sighandler_t)ps_cancel);
if ( v23 >= 0 )
{
LABEL_13:
for ( k = 0; k <= v23; ++k )
{
buf = v22;
v27 = k + v25;
if ( write(HIDWORD(v20[k % v3]), &buf, 8uLL) != 8 )
ps_error(13LL);
}
if ( v3 <= 0 )
goto LABEL_46;
goto LABEL_42;
}
LABEL_46:
signal(2, 0LL);
}
while ( v29 == -1 );
if ( !v30 )
close(fd);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
void *v4; // rsp
int k; // ebx
int i; // er12
int *v7; // rbx
__pid_t v8; // eax
int *v9; // rbx
__int64 v10; // r13
size_t v11; // rax
size_t v12; // rax
size_t v13; // rax
int v14; // ebx
int *v16; // rbx
int j; // ebx
unsigned __int16 v18; // bx
void *v19; // rsp
__int64 v20[2]; // [rsp+0h] [rbp-280h] BYREF
int fd; // [rsp+10h] [rbp-270h]
in_addr_t v22; // [rsp+14h] [rbp-26Ch]
int v23; // [rsp+18h] [rbp-268h]
unsigned __int16 v24; // [rsp+1Ch] [rbp-264h]
unsigned __int16 v25; // [rsp+1Eh] [rbp-262h]
unsigned int buf; // [rsp+28h] [rbp-258h] BYREF
unsigned __int16 v27; // [rsp+2Ch] [rbp-254h]
char s[256]; // [rsp+30h] [rbp-250h] BYREF
int v29; // [rsp+130h] [rbp-150h] BYREF
int v30; // [rsp+134h] [rbp-14Ch]
char *file; // [rsp+138h] [rbp-148h]
char cp[256]; // [rsp+140h] [rbp-140h] BYREF
unsigned __int16 v33; // [rsp+240h] [rbp-40h]
unsigned __int16 v34; // [rsp+242h] [rbp-3Eh]
unsigned __int16 v35; // [rsp+244h] [rbp-3Ch]
unsigned __int16 v36; // [rsp+246h] [rbp-3Ah]

func3(argc, (char **)argv, (__int64)&v29);
if ( !v30 )
{
fd = open(file, 577);
if ( fd < 0 )
ps_error(0LL);
}
do
{
v20[1] = (__int64)v20;
if ( v29 == -1 && (unsigned int)_isoc99_scanf("%s", cp) == -1 )
break;
v22 = inet_addr(cp);
if ( v22 == -1 )
{
v22 = ps_getip(cp);
if ( v22 == -1 )
ps_error(3LL);
}
v25 = v34;
if ( !v34 )
ps_error(4LL);
v18 = v35;
if ( !v35 )
ps_error(5LL);
v24 = v36;
if ( !v36 )
ps_error(7LL);
if ( v25 > v18 )
ps_error(6LL);
if ( v33 )
{
v23 = v18 - v25;
v3 = v23 + 1;
if ( v23 + 1 > v33 )
v3 = v33;
v19 = alloca(8LL * v3);
v7 = (int *)v20;
v20[0] = (__int64)v20;
if ( v3 > 0 )
{
for ( i = 0; i != v3; ++i )
{
if ( pipe(v7) < 0 )
ps_error(8LL);
v8 = fork();
if ( v8 < 0 )
{
ps_error(9LL);
}
else if ( !v8 )
{
close(HIDWORD(v20[i]));
if ( i > 0 )
{
v9 = (int *)v20 + 1;
v10 = v20[0] + 8LL * (unsigned int)(i - 1) + 12;
do
{
close(*v9);
v9 += 2;
}
while ( v9 != (int *)v10 );
}
while ( read(v20[i], &buf, 8uLL) == 8 )
{
if ( !v30 )
{
sprintf(s, "Child %d started scanning...\n", (unsigned int)i);
v11 = strlen(s);
write(fd, s, v11);
}
v14 = ps_scan(buf, v27, v24);
if ( !v30 )
{
sprintf(s, "Child %d finished.\n", (unsigned int)i);
v12 = strlen(s);
write(fd, s, v12);
}
if ( v14 )
{
if ( v14 == 1 )
{
sprintf(s, "%s %d SUCCESS\n", cp, v27);
}
else if ( v14 == 2 )
{
sprintf(s, "%s %d TIMEOUT\n", cp, v27);
}
}
else
{
sprintf(s, "%s %d ERROR\n", cp, v27);
}
v13 = strlen(s);
write(1, s, v13);
}
close(v20[i]);
return 0;
}
close(*v7);
v7 += 2;
}
signal(2, (__sighandler_t)ps_cancel);
if ( v23 >= 0 )
goto LABEL_13;
LABEL_42:
v16 = (int *)v20 + 1;
do
{
close(*v16);
v16 += 2;
}
while ( v16 != (int *)((char *)&v20[(unsigned int)(v3 - 1) + 1] + 4) );
for ( j = 0; j != v3; ++j )
wait(0LL);
goto LABEL_46;
}
}
else
{
ps_error(2LL);
v23 = v18 - v25;
v3 = v23 + 1;
if ( v23 + 1 > 0 )
v3 = 0;
v4 = alloca(8LL * v3);
}
signal(2, (__sighandler_t)ps_cancel);
if ( v23 >= 0 )
{
LABEL_13:
for ( k = 0; k <= v23; ++k )
{
buf = v22;
v27 = k + v25;
if ( write(HIDWORD(v20[k % v3]), &buf, 8uLL) != 8 )
ps_error(13LL);
}
if ( v3 <= 0 )
goto LABEL_46;
goto LABEL_42;
}
LABEL_46:
signal(2, 0LL);
}
while ( v29 == -1 );
if ( !v30 )
close(fd);
return 0;
}

original_code:
int main( int argc, char *argv[] )
{
   struct options_t options;
   in_addr_t ip;
   int fd;
   int buflen;
   unsigned short port;
   unsigned short minport;
   unsigned short maxport;
   unsigned short timeout;
   char str[255];
   int pid;
   int childs;
   ps_scan_t ret;
   int i;
   int j;
   ps_parse_options( argc, argv, &options );
   if (options.log == 0)
   {
      if ((fd = open( options.filename, 01 | 0100 | 01000 )) < 0)
      {
         ps_error( WARNING_LOG_FILENAME );
         options.log == -1;
      }
   }
   do
   {
      if (options.from_stdin == -1)
         if (scanf( "%s", options.ip ) == -1)
            break;
      if ((ip = inet_addr( options.ip )) == (in_addr_t)(-1))
         if ((ip = ps_getip( options.ip )) == (-1))
            ps_error( ERROR_HOST_INCORRECT );
      if (!(minport = options.minport))
         ps_error( ERROR_PORT_MIN );
      if (!(maxport = options.maxport))
         ps_error( ERROR_PORT_MAX );
      if (!(timeout = options.timeout))
         ps_error( ERROR_TIMEOUT );
      if (maxport < minport)
         ps_error( ERROR_PORT_RANGE );
      if (!(childs = options.maxchilds))
         ps_error( ERROR_MAX_CHILDS );
      if (childs > maxport - minport + 1)
         childs = maxport - minport + 1;
      int pfd[childs][2];
      struct scan_info_t scan_info;
      for (i = 0; i < childs; i++)
      {
         if (pipe( pfd[i] ) < 0)
            ps_error( ERROR_PIPE );
         pid = fork();
         if (pid < 0)
            ps_error( ERROR_FORK );
         else if (!pid)
         {
            close( pfd[i][1] );
            for (j = 0; j < i; j++)
               close( pfd[j][1] );
            while (read( pfd[i][0], &scan_info, sizeof (struct scan_info_t) ) == sizeof (struct scan_info_t))
            {
               if (options.log == 0)
               {
                  sprintf( str, "Child %d started scanning...\n", i );
                  write( fd, str, strlen( str ) );
               }
               ret = ps_scan( scan_info.ip, scan_info.port, timeout );
               if (options.log == 0)
               {
                  sprintf( str, "Child %d finished.\n", i );
                  write( fd, str, strlen( str ) );
               }
               if (ret == SCAN_ERROR)
                  sprintf( str, "%s %d ERROR\n", options.ip, scan_info.port );
               if (ret == SCAN_SUCCESS)
                  sprintf( str, "%s %d SUCCESS\n", options.ip, scan_info.port );
               if (ret == SCAN_TIMEOUT)
                  sprintf( str, "%s %d TIMEOUT\n", options.ip, scan_info.port );
               write( 1, str, strlen( str ) );
            }
            close( pfd[i][0] );
            return (PS_EXIT_STATUS_SUCCESS);
         }
         close( pfd[i][0] );
      }
      if (signal( 2, ps_cancel ) < 0)
         ps_error( WARNING_SIGNAL );
      for (i = 0; i < maxport - minport + 1; i++)
      {
         scan_info.ip = ip;
         scan_info.port = minport + i;
         if (write( pfd[i % childs][1], &scan_info, sizeof (struct scan_info_t) ) != sizeof (struct scan_info_t))
            ps_error( ERROR_PIPE_WRITE );
      }
      for (i = 0; i < childs; i++)
         close( pfd[i][1] );
      for (i = 0; i < childs; i++)
         wait( ((void *)0) );
      if (signal( 2, ((__sighandler_t) 0) ) < 0)
         ps_error( WARNING_SIGNAL );
   } while (options.from_stdin == -1);
   if (options.log == 0)
      close( fd );
   return (PS_EXIT_STATUS_SUCCESS);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   struct options_t options;
   unsigned int ip;
   int fd;
   int buflen;
   unsigned short port;
   unsigned short minport;
   unsigned short maxport;
   unsigned short timeout;
   char str[255];
   int pid;
   int childs;
   enum ps_scan_t ret;
   int i;
   int j;
   ps_parse_options( argc, argv, &options );
   if (options.log == 0)
   {
      if ((fd = open( options.filename, 01 | 0100 | 01000 )) < 0)
      {
         ps_error( WARNING_LOG_FILENAME );
         options.log == -1;
      }
   }
   do
   {
      if (options.from_stdin == -1)
         if (scanf( "%s", options.ip ) == -1)
            break;
      if ((ip = inet_addr( options.ip )) == (in_addr_t)(-1))
         if ((ip = ps_getip( options.ip )) == (-1))
            ps_error( ERROR_HOST_INCORRECT );
      if (!(minport = options.minport))
         ps_error( ERROR_PORT_MIN );
      if (!(maxport = options.maxport))
         ps_error( ERROR_PORT_MAX );
      if (!(timeout = options.timeout))
         ps_error( ERROR_TIMEOUT );
      if (maxport < minport)
         ps_error( ERROR_PORT_RANGE );
      if (!(childs = options.maxchilds))
         ps_error( ERROR_MAX_CHILDS );
      if (childs > maxport - minport + 1)
         childs = maxport - minport + 1;
      int pfd[-1][2];
      struct scan_info_t scan_info;
      for (i = 0; i < childs; i++)
      {
         if (pipe( pfd[i] ) < 0)
            ps_error( ERROR_PIPE );
         pid = fork();
         if (pid < 0)
            ps_error( ERROR_FORK );
         else if (!pid)
         {
            close( pfd[i][1] );
            for (j = 0; j < i; j++)
               close( pfd[j][1] );
            while (read( pfd[i][0], &scan_info, sizeof (struct scan_info_t) ) == sizeof (struct scan_info_t))
            {
               if (options.log == 0)
               {
                  sprintf( str, "Child %d started scanning...\n", i );
                  write( fd, str, strlen( str ) );
               }
               ret = ps_scan( scan_info.ip, scan_info.port, timeout );
               if (options.log == 0)
               {
                  sprintf( str, "Child %d finished.\n", i );
                  write( fd, str, strlen( str ) );
               }
               if (ret == SCAN_ERROR)
                  sprintf( str, "%s %d ERROR\n", options.ip, scan_info.port );
               if (ret == SCAN_SUCCESS)
                  sprintf( str, "%s %d SUCCESS\n", options.ip, scan_info.port );
               if (ret == SCAN_TIMEOUT)
                  sprintf( str, "%s %d TIMEOUT\n", options.ip, scan_info.port );
               write( 1, str, strlen( str ) );
            }
            close( pfd[i][0] );
            return (PS_EXIT_STATUS_SUCCESS);
         }
         close( pfd[i][0] );
      }
      if (signal( 2, ps_cancel ) < 0)
         ps_error( WARNING_SIGNAL );
      for (i = 0; i < maxport - minport + 1; i++)
      {
         scan_info.ip = ip;
         scan_info.port = minport + i;
         if (write( pfd[i % childs][1], &scan_info, sizeof (struct scan_info_t) ) != sizeof (struct scan_info_t))
            ps_error( ERROR_PIPE_WRITE );
      }
      for (i = 0; i < childs; i++)
         close( pfd[i][1] );
      for (i = 0; i < childs; i++)
         wait( ((void *)0) );
      if (signal( 2, ((void (*)(int)) 0) ) < 0)
         ps_error( WARNING_SIGNAL );
   } while (options.from_stdin == -1);
   if (options.log == 0)
      close( fd );
   return (PS_EXIT_STATUS_SUCCESS);
}

variable_types: struct options_t { int from_stdin; int log; char *filename; char ip[255]; unsigned short maxchilds; unsigned short minport; unsigned short maxport; unsigned short timeout; }

variable_types:
ip
unsigned int

variable_types: fd int

variable_types: buflen int

variable_types:
port
unsigned short

variable_types:
minport
unsigned short

variable_types:
maxport
unsigned short

variable_types:
timeout
unsigned short

variable_types: pid int

variable_types: childs int

variable_types: enum ps_scan_t { SCAN_ERROR=0, SCAN_SUCCESS=1, SCAN_TIMEOUT=2 }

variable_types: i int

variable_types: struct scan_info_t { unsigned int ip; unsigned short port; }


decompiled_code:
in_addr_t __fastcall ps_getip(const char *a1)
{
struct hostent *v1; // rax
unsigned int v2; // edx
in_addr_t result; // eax
char v4[24]; // [rsp+0h] [rbp-18h] BYREF

v1 = gethostbyname(a1);
if ( !v1 )
return -1;
v2 = (unsigned int)inet_ntop(2, *(const void **)v1->h_addr_list, v4, 0x10u);
result = -1;
if ( v2 )
result = inet_addr(v4);
return result;
}

canonical_decompiled_code:
in_addr_t __fastcall func0(const char *a1)
{
struct hostent *v1; // rax
unsigned int v2; // edx
in_addr_t result; // eax
char v4[24]; // [rsp+0h] [rbp-18h] BYREF

v1 = gethostbyname(a1);
if ( !v1 )
return -1;
v2 = (unsigned int)inet_ntop(2, *(const void **)v1->h_addr_list, v4, 0x10u);
result = -1;
if ( v2 )
result = inet_addr(v4);
return result;
}

original_code:
in_addr_t ps_getip( char *host )
{
   struct hostent *hent;
   char ip[16];
   if ((hent = gethostbyname( host )) == ((void *)0))
      return (-1);
   if (inet_ntop( 2, (void *)hent->h_addr_list[0], ip, sizeof (ip) ) == 0)
      return (-1);
   return (inet_addr( ip ));
}

canonical_original_code:
unsigned int ps_getip(char *host)
{
   struct hostent *hent;
   char ip[16];
   if ((hent = gethostbyname( host )) == ((void *)0))
      return (-1);
   if (inet_ntop( 2, (void *)hent->h_addr_list[0], ip, sizeof (ip) ) == 0)
      return (-1);
   return (inet_addr( ip ));
}

variable_types:
host
char *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types:
ip
char [16]

return_type: unsigned int


decompiled_code:
int __fastcall ps_set_nonblock(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3, 0LL);
BYTE1(v1) |= 8u;
return fcntl(fd, 4, v1);
}

canonical_decompiled_code:
int __fastcall func1(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3, 0LL);
BYTE1(v1) |= 8u;
return fcntl(fd, 4, v1);
}

original_code:
int ps_set_nonblock( int sock )
{
   int flags;
   flags = fcntl( sock, 3, ((void *)0) );
   return (fcntl( sock, 4, flags | 04000 ));
}

canonical_original_code:
int ps_set_nonblock(int sock)
{
   int flags;
   flags = fcntl( sock, 3, ((void *)0) );
   return (fcntl( sock, 4, flags | 04000 ));
}

variable_types: sock int

variable_types: flags int


decompiled_code:
__int64 __fastcall ps_scan(int a1, __int16 a2, unsigned __int16 a3)
{
int v4; // ebx
unsigned int v5; // ebp
int optval; // [rsp+8h] [rbp-D0h] BYREF
socklen_t optlen; // [rsp+Ch] [rbp-CCh] BYREF
fd_set writefds; // [rsp+10h] [rbp-C8h] BYREF
struct timeval timeout; // [rsp+90h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+A0h] [rbp-38h] BYREF

v4 = socket(2, 1, 6);
if ( v4 < 0 )
ps_error(10LL);
if ( ps_set_nonblock(v4) < 0 )
ps_error(11LL);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = a1;
*(_WORD *)addr.sa_data = _bswap_16(a2);
connect(v4, &addr, 0x10u);
v5 = 0;
if ( *_errno_location() == 115 )
{
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v4 / 64] |= 1LL << (v4 % 64);
timeout.tv_sec = a3 / 0x3E8u;
timeout.tv_usec = 1000 * (a3 - 1000 * timeout.tv_sec);
v5 = 2;
if ( select(v4 + 1, 0LL, &writefds, 0LL, &timeout) )
{
optlen = 4;
getsockopt(v4, 1, 4, &optval, &optlen);
v5 = optval == 0;
}
}
close(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int16 a2, unsigned __int16 a3)
{
int v4; // ebx
unsigned int v5; // ebp
int optval; // [rsp+8h] [rbp-D0h] BYREF
socklen_t optlen; // [rsp+Ch] [rbp-CCh] BYREF
fd_set writefds; // [rsp+10h] [rbp-C8h] BYREF
struct timeval timeout; // [rsp+90h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+A0h] [rbp-38h] BYREF

v4 = socket(2, 1, 6);
if ( v4 < 0 )
ps_error(10LL);
if ( func1(v4) < 0 )
ps_error(11LL);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = a1;
*(_WORD *)addr.sa_data = func0(a2);
connect(v4, &addr, 0x10u);
v5 = 0;
if ( *_errno_location() == 115 )
{
memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[v4 / 64] |= 1LL << (v4 % 64);
timeout.tv_sec = a3 / 0x3E8u;
timeout.tv_usec = 1000 * (a3 - 1000 * timeout.tv_sec);
v5 = 2;
if ( select(v4 + 1, 0LL, &writefds, 0LL, &timeout) )
{
optlen = 4;
getsockopt(v4, 1, 4, &optval, &optlen);
v5 = optval == 0;
}
}
close(v4);
return v5;
}

original_code:
ps_scan_t ps_scan( in_addr_t ip, unsigned short port, unsigned short timeout_msec )
{
   int sock;
   struct sockaddr_in target;
   struct timeval timeout;
   fd_set fdset;
   socklen_t lon;
   int valopt;
   ps_scan_t ret;
   if ((sock = socket( 2, SOCK_STREAM, IPPROTO_TCP )) < 0)
      ps_error( ERROR_SOCKET_SOCKET );
   if (ps_set_nonblock( sock ) < 0)
      ps_error( ERROR_SOCKET_NONBLOCK );
   target.sin_family = 2;
   target.sin_addr.s_addr = ip;
   target.sin_port = htons( port );
   connect( sock, (struct sockaddr *) &target, sizeof (struct sockaddr) );
   if ((*__errno_location ()) == 115)
   {
      do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdset)->__fds_bits)[0]) : "memory"); } while (0);
      ((void) (((&fdset)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
      timeout.tv_sec = timeout_msec / 1000;
      timeout.tv_usec = (timeout_msec - timeout.tv_sec * 1000) * 1000;
      if (select( sock + 1, ((void *)0), &fdset, ((void *)0), &timeout ))
      {
         lon = sizeof (int);
         getsockopt( sock, 1, 4, (void*)(&valopt), &lon );
         if (valopt)
            ret = SCAN_ERROR;
         else
            ret = SCAN_SUCCESS;
      }
      else
         ret = SCAN_TIMEOUT;
   }
   else
      ret = SCAN_ERROR;
   close( sock );
   return (ret);
}

canonical_original_code:
enum ps_scan_t ps_scan(unsigned int ip, unsigned short port, unsigned short timeout_msec)
{
   int sock;
   struct sockaddr_in target;
   struct timeval timeout;
   struct fd_set fdset;
   unsigned int lon;
   int valopt;
   enum ps_scan_t ret;
   if ((sock = socket( 2, SOCK_STREAM, IPPROTO_TCP )) < 0)
      ps_error( ERROR_SOCKET_SOCKET );
   if (ps_set_nonblock( sock ) < 0)
      ps_error( ERROR_SOCKET_NONBLOCK );
   target.sin_family = 2;
   target.sin_addr.s_addr = ip;
   target.sin_port = htons( port );
   connect( sock, (struct sockaddr *) &target, sizeof (struct sockaddr) );
   if ((*__errno_location ()) == 115)
   {
      do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdset)->__fds_bits)[0]) : "memory"); } while (0);
      ((void) (((&fdset)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
      timeout.tv_sec = timeout_msec / 1000;
      timeout.tv_usec = (timeout_msec - timeout.tv_sec * 1000) * 1000;
      if (select( sock + 1, ((void *)0), &fdset, ((void *)0), &timeout ))
      {
         lon = sizeof (int);
         getsockopt( sock, 1, 4, (void *)(&valopt), &lon );
         if (valopt)
            ret = SCAN_ERROR;
         else
            ret = SCAN_SUCCESS;
      }
      else
         ret = SCAN_TIMEOUT;
   }
   else
      ret = SCAN_ERROR;
   close( sock );
   return (ret);
}

variable_types:
ip
unsigned int

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

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

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

variable_types:
lon
unsigned int

variable_types: valopt int

return_type: enum ps_scan_t { SCAN_ERROR=0, SCAN_SUCCESS=1, SCAN_TIMEOUT=2 }

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

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


decompiled_code:
void __fastcall ps_error(int a1)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // rax
size_t v4; // rax
size_t v5; // rax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
const char *v9; // rsi
__int64 v10; // rcx
char *v11; // rdi
size_t v12; // rax
const char *v13; // rsi
__int64 v14; // rcx
char *v15; // rdi
size_t v16; // rax
size_t v17; // rax
const char *v18; // rsi
__int64 v19; // rcx
char *v20; // rdi
size_t v21; // rax
size_t v22; // rax
size_t v23; // rax
char v24[264]; // [rsp+0h] [rbp-108h] BYREF

switch ( a1 )
{
case 0:
strcpy(v24, "Failed while opening the log file.\n");
v1 = strlen(v24);
write(2, v24, v1);
break;
case 1:
strcpy(v24, "Failed while executing signal() function.\n");
v2 = strlen(v24);
write(2, v24, v2);
break;
case 2:
strcpy(v24, "Incorrect number of max childs.\n");
v3 = strlen(v24);
write(2, v24, v3);
exit(2);
case 3:
strcpy(v24, "Incorrect host address.\n");
v4 = strlen(v24);
write(2, v24, v4);
exit(2);
case 4:
strcpy(v24, "Incorrect start port.\n");
v5 = strlen(v24);
write(2, v24, v5);
exit(2);
case 5:
strcpy(v24, "Incorrect final port.\n");
v6 = strlen(v24);
write(2, v24, v6);
exit(2);
case 6:
strcpy(v24, "Initial port must be equal or higher than final port.\n");
v7 = strlen(v24);
write(2, v24, v7);
exit(2);
case 7:
strcpy(v24, "Incorrect timeout.\n");
v8 = strlen(v24);
write(2, v24, v8);
exit(2);
case 8:
v9 = "Error while executing pipe() function.\n";
v10 = 10LL;
v11 = v24;
while ( v10 )
{
*(_DWORD *)v11 = *(_DWORD *)v9;
v9 += 4;
v11 += 4;
--v10;
}
v12 = strlen(v24);
write(2, v24, v12);
exit(2);
case 9:
v13 = "Error while executing fork() function.\n";
v14 = 10LL;
v15 = v24;
while ( v14 )
{
*(_DWORD *)v15 = *(_DWORD *)v13;
v13 += 4;
v15 += 4;
--v14;
}
v16 = strlen(v24);
write(2, v24, v16);
exit(2);
case 10:
strcpy(v24, "Error while executing socket() function.\n");
v17 = strlen(v24);
write(2, v24, v17);
exit(2);
case 11:
v18 = "Cannot set the unblocking socket mode.\n";
v19 = 10LL;
v20 = v24;
while ( v19 )
{
*(_DWORD *)v20 = *(_DWORD *)v18;
v18 += 4;
v20 += 4;
--v19;
}
v21 = strlen(v24);
write(2, v24, v21);
exit(2);
case 12:
strcpy(v24, "Error while executing read() to read from the pipe.\n");
v22 = strlen(v24);
write(2, v24, v22);
exit(2);
case 13:
strcpy(v24, "Error while executing write() to write to the pipe.\n");
v23 = strlen(v24);
write(2, v24, v23);
exit(2);
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // rax
size_t v4; // rax
size_t v5; // rax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
const char *v9; // rsi
__int64 v10; // rcx
char *v11; // rdi
size_t v12; // rax
const char *v13; // rsi
__int64 v14; // rcx
char *v15; // rdi
size_t v16; // rax
size_t v17; // rax
const char *v18; // rsi
__int64 v19; // rcx
char *v20; // rdi
size_t v21; // rax
size_t v22; // rax
size_t v23; // rax
char v24[264]; // [rsp+0h] [rbp-108h] BYREF

switch ( a1 )
{
case 0:
strcpy(v24, "Failed while opening the log file.\n");
v1 = strlen(v24);
write(2, v24, v1);
break;
case 1:
strcpy(v24, "Failed while executing signal() function.\n");
v2 = strlen(v24);
write(2, v24, v2);
break;
case 2:
strcpy(v24, "Incorrect number of max childs.\n");
v3 = strlen(v24);
write(2, v24, v3);
exit(2);
case 3:
strcpy(v24, "Incorrect host address.\n");
v4 = strlen(v24);
write(2, v24, v4);
exit(2);
case 4:
strcpy(v24, "Incorrect start port.\n");
v5 = strlen(v24);
write(2, v24, v5);
exit(2);
case 5:
strcpy(v24, "Incorrect final port.\n");
v6 = strlen(v24);
write(2, v24, v6);
exit(2);
case 6:
strcpy(v24, "Initial port must be equal or higher than final port.\n");
v7 = strlen(v24);
write(2, v24, v7);
exit(2);
case 7:
strcpy(v24, "Incorrect timeout.\n");
v8 = strlen(v24);
write(2, v24, v8);
exit(2);
case 8:
v9 = "Error while executing pipe() function.\n";
v10 = 10LL;
v11 = v24;
while ( v10 )
{
*(_DWORD *)v11 = *(_DWORD *)v9;
v9 += 4;
v11 += 4;
--v10;
}
v12 = strlen(v24);
write(2, v24, v12);
exit(2);
case 9:
v13 = "Error while executing fork() function.\n";
v14 = 10LL;
v15 = v24;
while ( v14 )
{
*(_DWORD *)v15 = *(_DWORD *)v13;
v13 += 4;
v15 += 4;
--v14;
}
v16 = strlen(v24);
write(2, v24, v16);
exit(2);
case 10:
strcpy(v24, "Error while executing socket() function.\n");
v17 = strlen(v24);
write(2, v24, v17);
exit(2);
case 11:
v18 = "Cannot set the unblocking socket mode.\n";
v19 = 10LL;
v20 = v24;
while ( v19 )
{
*(_DWORD *)v20 = *(_DWORD *)v18;
v18 += 4;
v20 += 4;
--v19;
}
v21 = strlen(v24);
write(2, v24, v21);
exit(2);
case 12:
strcpy(v24, "Error while executing read() to read from the pipe.\n");
v22 = strlen(v24);
write(2, v24, v22);
exit(2);
case 13:
strcpy(v24, "Error while executing write() to write to the pipe.\n");
v23 = strlen(v24);
write(2, v24, v23);
exit(2);
default:
return;
}
}

original_code:
void ps_error( ps_error_t err )
{
   char str[255];
   switch (err)
   {
      case WARNING_LOG_FILENAME:
         sprintf( str, "Failed while opening the log file.\n" );
         write( 2, str, strlen( str ) );
         break;
      case WARNING_SIGNAL:
         sprintf( str, "Failed while executing signal() function.\n" );
         write( 2, str, strlen( str ) );
         break;
      case ERROR_MAX_CHILDS:
         sprintf( str, "Incorrect number of max childs.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_HOST_INCORRECT:
         sprintf( str, "Incorrect host address.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_PORT_MIN:
         sprintf( str, "Incorrect start port.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_PORT_MAX:
         sprintf( str, "Incorrect final port.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_PORT_RANGE:
         sprintf( str, "Initial port must be equal or higher than final port.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_TIMEOUT:
         sprintf( str, "Incorrect timeout.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_PIPE:
         sprintf( str, "Error while executing pipe() function.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_FORK:
         sprintf( str, "Error while executing fork() function.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_SOCKET_SOCKET:
         sprintf( str, "Error while executing socket() function.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_SOCKET_NONBLOCK:
         sprintf( str, "Cannot set the unblocking socket mode.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_PIPE_READ:
         sprintf( str, "Error while executing read() to read from the pipe.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_PIPE_WRITE:
         sprintf( str, "Error while executing write() to write to the pipe.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      default:
         break;
   }
}

canonical_original_code:
void ps_error(enum ps_error_t err)
{
   char str[255];
   switch (err)
   {
      case WARNING_LOG_FILENAME:
         sprintf( str, "Failed while opening the log file.\n" );
         write( 2, str, strlen( str ) );
         break;
      case WARNING_SIGNAL:
         sprintf( str, "Failed while executing signal() function.\n" );
         write( 2, str, strlen( str ) );
         break;
      case ERROR_MAX_CHILDS:
         sprintf( str, "Incorrect number of max childs.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_HOST_INCORRECT:
         sprintf( str, "Incorrect host address.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_PORT_MIN:
         sprintf( str, "Incorrect start port.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_PORT_MAX:
         sprintf( str, "Incorrect final port.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_PORT_RANGE:
         sprintf( str, "Initial port must be equal or higher than final port.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_TIMEOUT:
         sprintf( str, "Incorrect timeout.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_PIPE:
         sprintf( str, "Error while executing pipe() function.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_FORK:
         sprintf( str, "Error while executing fork() function.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_SOCKET_SOCKET:
         sprintf( str, "Error while executing socket() function.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_SOCKET_NONBLOCK:
         sprintf( str, "Cannot set the unblocking socket mode.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_PIPE_READ:
         sprintf( str, "Error while executing read() to read from the pipe.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      case ERROR_PIPE_WRITE:
         sprintf( str, "Error while executing write() to write to the pipe.\n" );
         write( 2, str, strlen( str ) );
         exit (PS_EXIT_STATUS_ERROR);
      default:
         break;
   }
}

variable_types: enum ps_error_t { WARNING_LOG_FILENAME=0, WARNING_SIGNAL=1, ERROR_MAX_CHILDS=2, ERROR_HOST_INCORRECT=3, ERROR_PORT_MIN=4, ERROR_PORT_MAX=5, ERROR_PORT_RANGE=6, ERROR_TIMEOUT=7, ERROR_PIPE=8, ERROR_FORK=9, ERROR_SOCKET_SOCKET=10, ERROR_SOCKET_NONBLOCK=11, ERROR_PIPE_READ=12, ERROR_PIPE_WRITE=13 }

variable_types:
str
char [255]


repo: periodic/Shady

decompiled_code:
int print_test()
{
return printf("Test var: 0x%x\n", 3735928559LL);
}

canonical_decompiled_code:
int func7()
{
return printf("Test var: 0x%x\n", 3735928559LL);
}

original_code:
void
print_test()
{
    printf("Test var: 0x%x\n", testvar);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbp
__int64 i; // rbx

v3 = malloc(4uLL);
for ( i = 0LL; i != 4; ++i )
{
printf("Old %i: %x\n", (unsigned int)i, (unsigned int)v3[i]);
v3[i] = 269488144;
printf("New %i: %x\n", (unsigned int)i, 269488144LL);
}
print_test();
print_test();
print_test();
print_test();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbp
__int64 i; // rbx

v3 = malloc(4uLL);
for ( i = 0LL; i != 4; ++i )
{
printf("Old %i: %x\n", (unsigned int)i, (unsigned int)v3[i]);
v3[i] = 269488144;
printf("New %i: %x\n", (unsigned int)i, 269488144LL);
}
func7();
func7();
func7();
func7();
return 0;
}

original_code:
int
main (int argc, char** argv)
{
    int i;
    int* tmp = malloc(sizeof(int));
    for (i = 0; i < 4; i++)
    {
        printf("Old %i: %x\n", i, tmp[i]);
        tmp[i] = 0x10101010;
        printf("New %i: %x\n", i, tmp[i]);
    }
    for (i = 0; i < 4; i++)
    {
        print_test();
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int i;
    int *tmp = malloc(sizeof(int));
    for (i = 0; i < 4; i++)
    {
        printf("Old %i: %x\n", i, tmp[i]);
        tmp[i] = 0x10101010;
        printf("New %i: %x\n", i, tmp[i]);
    }
    for (i = 0; i < 4; i++)
    {
        print_test();
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
tmp
int *


repo: pervouchine/bamflag

canonical_original_code:
static void process_cns(struct bam_header_t *h, int tid, int l, unsigned short *cns)
{
 int i; int f[2][2]; int *prev; int *curr; int *swap_tmp; int s;
 unsigned char *b;
 b = calloc(l, 1);
 f[0][0] = f[0][1] = 0;
 prev = f[0]; curr = f[1];
 for (i = 0; i < l; ++i) {
  int c = (cns[i] == 0)? 0 : (cns[i]>>8 == 0)? 1 : 2;
  int tmp0; int tmp1;
  tmp0 = prev[0] + g_param.e[0][c] + g_param.p[0][0];
  tmp1 = prev[1] + g_param.e[0][c] + g_param.p[1][0];
  if (tmp0 > tmp1) curr[0] = tmp0, b[i] = 0;
  else curr[0] = tmp1, b[i] = 1;
  tmp0 = prev[0] + g_param.e[1][c] + g_param.p[0][1];
  tmp1 = prev[1] + g_param.e[1][c] + g_param.p[1][1];
  if (tmp0 > tmp1) curr[1] = tmp0, b[i] |= 0<<1;
  else curr[1] = tmp1, b[i] |= 1<<1;
  swap_tmp = prev; prev = curr; curr = swap_tmp;
 }
 s = prev[0] > prev[1]? 0 : 1;
 for (i = l - 1; i > 0; --i) {
  b[i] |= s<<2;
  s = b[i]>>s&1;
 }
 for (i = 0, s = -1; i <= l; ++i) {
  if (i == l || ((b[i]>>2&3) == 0 && s >= 0)) {
   if (s >= 0) {
    int j;
    printf("%s:%d-%d\t0\t%s\t%d\t60\t%dM\t*\t0\t0\t", h->target_name[tid], s+1, i, h->target_name[tid], s+1, i-s);
    for (j = s; j < i; ++j) {
     int c = cns[j]>>8;
     if (c == 0) putchar('N');
     else putchar("ACGT"[c&3]);
    }
    putchar('\t');
    for (j = s; j < i; ++j)
     putchar(33 + (cns[j]>>8>>2));
    putchar('\n');
   }
   s = -1;
  } else if ((b[i]>>2&3) && s < 0) s = i;
 }
 free(b);
}

variable_types: struct bam_header_t { int n_targets; char **target_name; unsigned int *target_len; void *dict; unsigned long l_text; char *text; } *

variable_types: tid int

variable_types: l int

variable_types:
cns
unsigned short *

variable_types: i int

variable_types:
prev
int *

variable_types:
curr
int *

variable_types: s int

variable_types:
b
unsigned char *

variable_types: c int

variable_types: j int


decompiled_code:
__int64 bam_is_big_endian()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
static inline int bam_is_big_endian()
{
 long one= 1;
 return !(*((char *)(&one)));
}

canonical_original_code:
static inline int bam_is_big_endian()
{
 long one = 1;
 return !(*((char *)(&one)));
}

variable_types: one long


decompiled_code:
__int64 __fastcall bam_swap_endian_4(int a1)
{
unsigned int v1; // edi

v1 = __ROL4__(a1, 16);
return (v1 >> 8) & 0xFF00FF | (v1 << 8) & 0xFF00FF00;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned int v1; // edi

v1 = __ROL4__(a1, 16);
return (v1 >> 8) & 0xFF00FF | (v1 << 8) & 0xFF00FF00;
}

original_code:
static inline uint32_t bam_swap_endian_4(uint32_t v)
{
 v = ((v & 0x0000FFFFU) << 16) | (v >> 16);
 return ((v & 0x00FF00FFU) << 8) | ((v & 0xFF00FF00U) >> 8);
}

canonical_original_code:
static inline unsigned int bam_swap_endian_4(unsigned int v)
{
 v = ((v & 0x0000FFFFU) << 16) | (v >> 16);
 return ((v & 0x00FF00FFU) << 8) | ((v & 0xFF00FF00U) >> 8);
}

variable_types:
v
unsigned int


decompiled_code:
unsigned __int64 __fastcall bam_swap_endian_8(__int64 a1)
{
unsigned __int64 v1; // rdi
unsigned __int64 v2; // rax

v1 = __ROL8__(a1, 32);
v2 = (v1 >> 16) & 0xFFFF0000FFFFLL | (v1 << 16) & 0xFFFF0000FFFF0000LL;
return (v2 << 8) & 0xFF00FF00FF00FF00LL | (v2 >> 8) & 0xFF00FF00FF00FFLL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1)
{
unsigned __int64 v1; // rdi
unsigned __int64 v2; // rax

v1 = __ROL8__(a1, 32);
v2 = (v1 >> 16) & 0xFFFF0000FFFFLL | (v1 << 16) & 0xFFFF0000FFFF0000LL;
return (v2 << 8) & 0xFF00FF00FF00FF00LL | (v2 >> 8) & 0xFF00FF00FF00FFLL;
}

canonical_original_code:
static inline unsigned long bam_swap_endian_8(unsigned long v)
{
 v = ((v & 0x00000000FFFFFFFFLLU) << 32) | (v >> 32);
 v = ((v & 0x0000FFFF0000FFFFLLU) << 16) | ((v & 0xFFFF0000FFFF0000LLU) >> 16);
 return ((v & 0x00FF00FF00FF00FFLLU) << 8) | ((v & 0xFF00FF00FF00FF00LLU) >> 8);
}

variable_types:
v
unsigned long

return_type: unsigned long


decompiled_code:
char *__fastcall get_local_version(char *src)
{
size_t v1; // rax
char *v2; // rbx
unsigned __int64 i; // rdi
char *v5; // rbp
struct stat64 v6; // [rsp+0h] [rbp-A8h] BYREF

v1 = strlen(src);
v2 = (char *)calloc(v1 + 5, 1uLL);
strcpy(v2, src);
strcat(v2, ".bci");
if ( v2 == strstr(v2, "ftp://") || v2 == strstr(v2, "http://") )
{
for ( i = (unsigned __int64)&v2[(int)strlen(v2) - 1]; (unsigned __int64)v2 <= i; --i )
{
if ( *(_BYTE *)i == 47 )
break;
}
v5 = strdup((const char *)(i + 1));
if ( !stat64(v5, &v6) )
{
free(v2);
return v5;
}
fprintf(stderr, "[%s] downloading the index file...\n", "get_local_version");
download_from_remote(v2);
free(v2);
v2 = v5;
}
if ( stat64(v2, &v6) )
{
free(v2);
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func7(char *src)
{
size_t v1; // rax
char *v2; // rbx
unsigned __int64 i; // rdi
char *v5; // rbp
struct stat64 v6; // [rsp+0h] [rbp-A8h] BYREF

v1 = strlen(src);
v2 = (char *)calloc(v1 + 5, 1uLL);
strcpy(v2, src);
strcat(v2, ".bci");
if ( v2 == strstr(v2, "ftp://") || v2 == strstr(v2, "http://") )
{
for ( i = (unsigned __int64)&v2[(int)strlen(v2) - 1]; (unsigned __int64)v2 <= i; --i )
{
if ( *(_BYTE *)i == 47 )
break;
}
v5 = strdup((const char *)(i + 1));
if ( !stat64(v5, &v6) )
{
free(v2);
return v5;
}
fprintf(stderr, "[%s] downloading the index file...\n", "get_local_version");
func6(v2);
free(v2);
v2 = v5;
}
if ( stat64(v2, &v6) )
{
free(v2);
v2 = 0LL;
}
return v2;
}

original_code:
static char *get_local_version(const char *fn)
{
    struct stat sbuf;
 char *fnidx = (char*)calloc(strlen(fn) + 5, 1);
 strcat(strcpy(fnidx, fn), ".bci");
 if ((strstr(fnidx, "ftp://") == fnidx || strstr(fnidx, "http://") == fnidx)) {
  char *p, *url;
  int l = strlen(fnidx);
  for (p = fnidx + l - 1; p >= fnidx; --p)
   if (*p == '/') break;
  url = fnidx; fnidx = strdup(p + 1);
  if (stat(fnidx, &sbuf) == 0) {
   free(url);
   return fnidx;
  }
  fprintf(stderr, "[%s] downloading the index file...\n", __func__);
  download_from_remote(url);
  free(url);
 }
    if (stat(fnidx, &sbuf) == 0) return fnidx;
 free(fnidx); return 0;
}

canonical_original_code:
static char *get_local_version(char *fn)
{
    struct stat sbuf;
 char *fnidx = (char*)calloc(strlen(fn) + 5, 1);
 strcat(strcpy(fnidx, fn), ".bci");
 if ((strstr(fnidx, "ftp://") == fnidx || strstr(fnidx, "http://") == fnidx)) {
  char *p; char *url;
  int l = strlen(fnidx);
  for (p = fnidx + l - 1; p >= fnidx; --p)
   if (*p == '/') break;
  url = fnidx; fnidx = strdup(p + 1);
  if (stat(fnidx, &sbuf) == 0) {
   free(url);
   return fnidx;
  }
  fprintf(stderr, "[%s] downloading the index file...\n", __func__);
  download_from_remote(url);
  free(url);
 }
    if (stat(fnidx, &sbuf) == 0) return fnidx;
 free(fnidx); return 0;
}

variable_types:
fn
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; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
fnidx
char *

variable_types:
p
char *

variable_types:
url
char *

return_type: char *

user_defined_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; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void __fastcall bcf_idx_destroy(void *ptr)
{
__int64 v1; // rbx

if ( ptr )
{
if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 1) + 16 * v1++ + 8));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
__int64 v1; // rbx

if ( ptr )
{
if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 1) + 16 * v1++ + 8));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void bcf_idx_destroy(bcf_idx_t *idx)
{
 int i;
 if (idx == 0) return;
 for (i = 0; i < idx->n; ++i) free(idx->index2[i].offset);
 free(idx->index2);
 free(idx);
}

canonical_original_code:
void bcf_idx_destroy(struct __bcf_idx_t *idx)
{
 int i;
 if (idx == 0) return;
 for (i = 0; i < idx->n; ++i) free(idx->index2[i].offset);
 free(idx->index2);
 free(idx);
}

variable_types: struct __bcf_idx_t { int n; struct bcf_lidx_t { int n; unsigned long *offset; } *index2; } *

user_defined_types: struct __bcf_idx_t { int n; struct bcf_lidx_t *index2; }


decompiled_code:
int *__fastcall bcf_idx_load(char *a1)
{
char *v1; // rax
char *v2; // rbx
int *v3; // rbp

v1 = get_local_version(a1);
v2 = v1;
if ( !v1 )
return 0LL;
v3 = bcf_idx_load_local((__int64)v1);
free(v2);
return v3;
}

canonical_decompiled_code:
int *__fastcall func10(char *a1)
{
char *v1; // rax
char *v2; // rbx
int *v3; // rbp

v1 = func7(a1);
v2 = v1;
if ( !v1 )
return 0LL;
v3 = func9((__int64)v1);
free(v2);
return v3;
}

original_code:
bcf_idx_t *bcf_idx_load(const char *fn)
{
 bcf_idx_t *idx;
    char *fname = get_local_version(fn);
 if (fname == 0) return 0;
 idx = bcf_idx_load_local(fname);
    free(fname);
 return idx;
}

canonical_original_code:
struct __bcf_idx_t *bcf_idx_load(char *fn)
{
 struct __bcf_idx_t *idx;
    char *fname = get_local_version(fn);
 if (fname == 0) return 0;
 idx = bcf_idx_load_local(fname);
    free(fname);
 return idx;
}

variable_types:
fname
char *

return_type: struct __bcf_idx_t { int n; struct bcf_lidx_t { int n; unsigned long *offset; } *index2; } *


original_code:
uint64_t bcf_idx_query(const bcf_idx_t *idx, int tid, int beg)
{
 uint64_t min_off, *offset;
 int i;
 if (beg < 0) beg = 0;
 offset = idx->index2[tid].offset;
 for (i = beg>>13; i < idx->index2[tid].n && offset[i] == 0; ++i);
 min_off = (i == idx->index2[tid].n)? offset[idx->index2[tid].n-1] : offset[i];
 return min_off;
}

canonical_original_code:
unsigned long bcf_idx_query(struct __bcf_idx_t *idx, int tid, int beg)
{
 unsigned long min_off; unsigned long *offset;
 int i;
 if (beg < 0) beg = 0;
 offset = idx->index2[tid].offset;
 for (i = beg>>13; i < idx->index2[tid].n && offset[i] == 0; ++i);
 min_off = (i == idx->index2[tid].n)? offset[idx->index2[tid].n-1] : offset[i];
 return min_off;
}

variable_types: tid int

variable_types: beg int

variable_types:
offset
unsigned long *

variable_types: i int

user_defined_types: struct bcf_lidx_t { int n; unsigned long *offset; }


decompiled_code:
__int64 __fastcall bcf_idx_build(char *a1)
{
return bcf_idx_build2(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(char *a1)
{
return func11(a1, 0LL);
}

original_code:
int bcf_idx_build(const char *fn)
{
 return bcf_idx_build2(fn, 0);
}

canonical_original_code:
int bcf_idx_build(char *fn)
{
 return bcf_idx_build2(fn, 0);
}


original_code:
int bcf_parse_region(void *str2id, const char *str, int *tid, int *begin, int *end)
{
 char *s, *p;
 int i, l, k;
 l = strlen(str);
 p = s = (char*)malloc(l+1);
 for (i = k = 0; i != l; ++i)
  if (str[i] != ',' && !((*__ctype_b_loc ())[(int) ((str[i]))] & (unsigned short int) _ISspace)) s[k++] = str[i];
 s[k] = 0;
 for (i = 0; i != k; ++i) if (s[i] == ':') break;
 s[i] = 0;
 if ((*tid = bcf_str2id(str2id, s)) < 0) {
  free(s);
  return -1;
 }
 if (i == k) {
  *begin = 0; *end = 1<<29; free(s);
  return 0;
 }
 for (p = s + i + 1; i != k; ++i) if (s[i] == '-') break;
 *begin = atoi(p);
 if (i < k) {
  p = s + i + 1;
  *end = atoi(p);
 } else *end = 1<<29;
 if (*begin > 0) --*begin;
 free(s);
 if (*begin > *end) return -1;
 return 0;
}

canonical_original_code:
int bcf_parse_region(void *str2id, char *str, int *tid, int *begin, int *end)
{
 char *s; char *p;
 int i; int l; int k;
 l = strlen(str);
 p = s = (char *)malloc(l+1);
 for (i = k = 0; i != l; ++i)
  if (str[i] != ',' && !((*__ctype_b_loc ())[(int) ((str[i]))] & (unsigned short) _ISspace)) s[k++] = str[i];
 s[k] = 0;
 for (i = 0; i != k; ++i) if (s[i] == ':') break;
 s[i] = 0;
 if ((*tid = bcf_str2id(str2id, s)) < 0) {
  free(s);
  return -1;
 }
 if (i == k) {
  *begin = 0; *end = 1<<29; free(s);
  return 0;
 }
 for (p = s + i + 1; i != k; ++i) if (s[i] == '-') break;
 *begin = atoi(p);
 if (i < k) {
  p = s + i + 1;
  *end = atoi(p);
 } else *end = 1<<29;
 if (*begin > 0) --*begin;
 free(s);
 if (*begin > *end) return -1;
 return 0;
}

variable_types:
str
char *

variable_types:
tid
int *

variable_types:
begin
int *

variable_types:
end
int *

variable_types:
s
char *

variable_types: l int

variable_types: k int


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

if ( a1 == 1 )
{
fwrite("Usage: bcftools index <in.bcf>\n", 1uLL, 0x1FuLL, stderr);
result = 1LL;
}
else
{
bcf_idx_build(*(char **)(a2 + 8));
result = 0LL;
}
return result;
}

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

if ( a1 == 1 )
{
fwrite("Usage: bcftools index <in.bcf>\n", 1uLL, 0x1FuLL, stderr);
result = 1LL;
}
else
{
func12(*(char **)(a2 + 8));
result = 0LL;
}
return result;
}

original_code:
int bcf_main_index(int argc, char *argv[])
{
 if (argc == 1) {
  fprintf(stderr, "Usage: bcftools index <in.bcf>\n");
  return 1;
 }
 bcf_idx_build(argv[1]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall bam_aux_getCSi(__int64 a1, int a2)
{
__int64 v3; // rdi
__int64 result; // rax
const char *v5; // r12
int v6; // eax

v3 = bam_aux_get(a1, &unk_2F6);
result = 0LL;
if ( v3 )
{
v5 = (const char *)bam_aux2Z();
v6 = a2 + 1;
if ( (*(_BYTE *)(a1 + 12) & 0x10) != 0 )
v6 = ~a2 + strlen(v5);
result = (unsigned __int8)v5[v6];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 v3; // rdi
__int64 result; // rax
const char *v5; // r12
int v6; // eax

v3 = bam_aux_get(a1, &unk_2F6);
result = 0LL;
if ( v3 )
{
v5 = (const char *)bam_aux2Z();
v6 = a2 + 1;
if ( (*(_BYTE *)(a1 + 12) & 0x10) != 0 )
v6 = ~a2 + strlen(v5);
result = (unsigned __int8)v5[v6];
}
return result;
}

original_code:
char bam_aux_getCSi(bam1_t *b, int i)
{
 uint8_t *c = bam_aux_get(b, "CS");
 char *cs = ((void *)0);
 if(0 == c) return 0;
 cs = bam_aux2Z(c);
 if((((b)->core.flag&16) != 0)) i = strlen(cs) - 1 - i;
 else i++;
 return cs[i];
}

canonical_original_code:
char bam_aux_getCSi(struct bam1_t *b, int i)
{
 unsigned char *c = bam_aux_get(b, "CS");
 char *cs = ((void *)0);
 if(0 == c) return 0;
 cs = bam_aux2Z(c);
 if((((b)->core.flag&16) != 0)) i = strlen(cs) - 1 - i;
 else i++;
 return cs[i];
}

variable_types: struct bam1_t { struct bam1_core_t { int tid; int pos; unsigned int bin; unsigned int flag; int l_qseq; int mtid; int mpos; int isize; } core; int l_aux; unsigned char *data; } *

variable_types:
c
unsigned char *

variable_types:
cs
char *

return_type: char

user_defined_types: struct bam1_t { struct bam1_core_t core; int l_aux; unsigned char *data; }


decompiled_code:
__int64 __fastcall bam_aux_getCQi(__int64 a1, int a2)
{
int v3; // ebx
__int64 v4; // rdi
__int64 result; // rax
const char *v6; // rax
const char *v7; // r12

v3 = a2;
v4 = bam_aux_get(a1, &unk_2F9);
result = 0LL;
if ( v4 )
{
v6 = (const char *)bam_aux2Z();
v7 = v6;
if ( (*(_BYTE *)(a1 + 12) & 0x10) != 0 )
v3 = strlen(v6) + ~a2;
result = (unsigned __int8)v7[v3];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v3; // ebx
__int64 v4; // rdi
__int64 result; // rax
const char *v6; // rax
const char *v7; // r12

v3 = a2;
v4 = bam_aux_get(a1, &unk_2F9);
result = 0LL;
if ( v4 )
{
v6 = (const char *)bam_aux2Z();
v7 = v6;
if ( (*(_BYTE *)(a1 + 12) & 0x10) != 0 )
v3 = strlen(v6) + ~a2;
result = (unsigned __int8)v7[v3];
}
return result;
}

original_code:
char bam_aux_getCQi(bam1_t *b, int i)
{
 uint8_t *c = bam_aux_get(b, "CQ");
 char *cq = ((void *)0);
 if(0 == c) return 0;
 cq = bam_aux2Z(c);
 if((((b)->core.flag&16) != 0)) i = strlen(cq) - 1 - i;
 return cq[i];
}

canonical_original_code:
char bam_aux_getCQi(struct bam1_t *b, int i)
{
 unsigned char *c = bam_aux_get(b, "CQ");
 char *cq = ((void *)0);
 if(0 == c) return 0;
 cq = bam_aux2Z(c);
 if((((b)->core.flag&16) != 0)) i = strlen(cq) - 1 - i;
 return cq[i];
}

variable_types:
cq
char *

user_defined_types: struct bam1_core_t { int tid; int pos; unsigned int bin; unsigned int flag; int l_qseq; int mtid; int mpos; int isize; }


original_code:
char bam_aux_getCEi(bam1_t *b, int i)
{
 int cs_i;
 uint8_t *c = bam_aux_get(b, "CS");
 char *cs = ((void *)0);
 char prev_b, cur_b;
 char cur_color, cor_color;
 if(0 == c) return 0;
 cs = bam_aux2Z(c);
 if((((b)->core.flag&16) != 0)) {
  cs_i = strlen(cs) - 1 - i;
  cur_color = cs[cs_i];
  prev_b = (cs_i == 1) ? "TGCAN"[(int)bam_aux_nt2int(cs[0])] : bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i+1)/2] >> 4*(1-(i+1)%2) & 0xf)];
  cur_b = bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i)/2] >> 4*(1-(i)%2) & 0xf)];
 }
 else {
  cs_i=i+1;
  cur_color = cs[cs_i];
  prev_b = (0 == i) ? cs[0] : bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i-1)/2] >> 4*(1-(i-1)%2) & 0xf)];
  cur_b = bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i)/2] >> 4*(1-(i)%2) & 0xf)];
 }
 cor_color = bam_aux_ntnt2cs(prev_b, cur_b);
 if(cur_color == cor_color) {
  return '-';
 }
 else {
  return cur_color;
 }
}

canonical_original_code:
char bam_aux_getCEi(struct bam1_t *b, int i)
{
 int cs_i;
 unsigned char *c = bam_aux_get(b, "CS");
 char *cs = ((void *)0);
 char prev_b; char cur_b;
 char cur_color; char cor_color;
 if(0 == c) return 0;
 cs = bam_aux2Z(c);
 if((((b)->core.flag&16) != 0)) {
  cs_i = strlen(cs) - 1 - i;
  cur_color = cs[cs_i];
  prev_b = (cs_i == 1) ? "TGCAN"[(int)bam_aux_nt2int(cs[0])] : bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i+1)/2] >> 4*(1-(i+1)%2) & 0xf)];
  cur_b = bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i)/2] >> 4*(1-(i)%2) & 0xf)];
 }
 else {
  cs_i=i+1;
  cur_color = cs[cs_i];
  prev_b = (0 == i) ? cs[0] : bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i-1)/2] >> 4*(1-(i-1)%2) & 0xf)];
  cur_b = bam_nt16_rev_table[((((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname))[(i)/2] >> 4*(1-(i)%2) & 0xf)];
 }
 cor_color = bam_aux_ntnt2cs(prev_b, cur_b);
 if(cur_color == cor_color) {
  return '-';
 }
 else {
  return cur_color;
 }
}


decompiled_code:
__int64 __fastcall bam_aux_nt2int(char a1)
{
const __int32_t *v1; // rax
int v2; // edx
__int64 result; // rax

v1 = *_ctype_toupper_loc();
v2 = v1[a1];
if ( v2 == 71 )
return 2LL;
if ( v2 > 71 )
{
LOBYTE(v1) = v2 != 84;
result = (unsigned int)((_DWORD)v1 + 3);
}
else
{
result = 0LL;
if ( v2 != 65 )
{
LOBYTE(result) = v2 != 67;
result = (unsigned int)(3 * result + 1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
const __int32_t *v1; // rax
int v2; // edx
__int64 result; // rax

v1 = *_ctype_toupper_loc();
v2 = v1[a1];
if ( v2 == 71 )
return 2LL;
if ( v2 > 71 )
{
LOBYTE(v1) = v2 != 84;
result = (unsigned int)((_DWORD)v1 + 3);
}
else
{
result = 0LL;
if ( v2 != 65 )
{
LOBYTE(result) = v2 != 67;
result = (unsigned int)(3 * result + 1);
}
}
return result;
}

original_code:
char bam_aux_nt2int(char a)
{
 switch(toupper(a)) {
  case 'A':
   return 0;
   break;
  case 'C':
   return 1;
   break;
  case 'G':
   return 2;
   break;
  case 'T':
   return 3;
   break;
  default:
   return 4;
   break;
 }
}

variable_types: a char


decompiled_code:
__int64 __fastcall bam_aux_ntnt2cs(char a1, char a2)
{
char v2; // bl
char v3; // al
__int64 result; // rax

v2 = bam_aux_nt2int(a1);
v3 = bam_aux_nt2int(a2);
if ( v2 == 4 || v3 == 4 )
result = 52LL;
else
result = (unsigned __int8)byte_2FC[(char)(v3 ^ v2)];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1, char a2)
{
char v2; // bl
char v3; // al
__int64 result; // rax

v2 = func2(a1);
v3 = func2(a2);
if ( v2 == 4 || v3 == 4 )
result = 52LL;
else
result = (unsigned __int8)byte_2FC[(char)(v3 ^ v2)];
return result;
}

original_code:
char bam_aux_ntnt2cs(char a, char b)
{
 a = bam_aux_nt2int(a);
 b = bam_aux_nt2int(b);
 if(4 == a || 4 == b) return '4';
 return "0123"[(int)(a ^ b)];
}

variable_types: b char


ksprintf

original_code:
int ksprintf(kstring_t *s, const char *fmt, ...)
{
 va_list ap;
 int l;
 __builtin_va_start(ap,fmt);
 l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
 __builtin_va_end(ap);
 if (l + 1 > s->m - s->l) {
  s->m = s->l + l + 2;
  (--(s->m), (s->m)|=(s->m)>>1, (s->m)|=(s->m)>>2, (s->m)|=(s->m)>>4, (s->m)|=(s->m)>>8, (s->m)|=(s->m)>>16, ++(s->m));
  s->s = (char*)realloc(s->s, s->m);
  __builtin_va_start(ap,fmt);
  l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
 }
 __builtin_va_end(ap);
 s->l += l;
 return l;
}

canonical_original_code:
int ksprintf(struct __kstring_t *s, char *fmt, ...)
{
 __builtin_va_list ap;
 int l;
 __builtin_va_start(ap,fmt);
 l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
 __builtin_va_end(ap);
 if (l + 1 > s->m - s->l) {
  s->m = s->l + l + 2;
  (--(s->m), (s->m)|=(s->m)>>1, (s->m)|=(s->m)>>2, (s->m)|=(s->m)>>4, (s->m)|=(s->m)>>8, (s->m)|=(s->m)>>16, ++(s->m));
  s->s = (char *)realloc(s->s, s->m);
  __builtin_va_start(ap,fmt);
  l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
 }
 __builtin_va_end(ap);
 s->l += l;
 return l;
}

variable_types: struct __kstring_t { unsigned long l; char *s; } *

variable_types:
fmt
char *


kstrtok

original_code:
char *kstrtok(const char *str, const char *sep, ks_tokaux_t *aux)
{
 const char *p, *start;
 if (sep) {
  if (str == 0 && (aux->tab[0]&1)) return 0;
  aux->finished = 0;
  if (sep[1]) {
   aux->sep = -1;
   aux->tab[0] = aux->tab[1] = aux->tab[2] = aux->tab[3] = 0;
   for (p = sep; *p; ++p) aux->tab[*p>>6] |= 1ull<<(*p&0x3f);
  } else aux->sep = sep[0];
 }
 if (aux->finished) return 0;
 else if (str) aux->p = str - 1, aux->finished = 0;
 if (aux->sep < 0) {
  for (p = start = aux->p + 1; *p; ++p)
   if (aux->tab[*p>>6]>>(*p&0x3f)&1) break;
 } else {
  for (p = start = aux->p + 1; *p; ++p)
   if (*p == aux->sep) break;
 }
 aux->p = p;
 if (*p == 0) aux->finished = 1;
 return (char*)start;
}

canonical_original_code:
char *kstrtok(char *str, char *sep, struct ks_tokaux_t *aux)
{
 char *p; char *start;
 if (sep) {
  if (str == 0 && (aux->tab[0]&1)) return 0;
  aux->finished = 0;
  if (sep[1]) {
   aux->sep = -1;
   aux->tab[0] = aux->tab[1] = aux->tab[2] = aux->tab[3] = 0;
   for (p = sep; *p; ++p) aux->tab[*p>>6] |= 1ull<<(*p&0x3f);
  } else aux->sep = sep[0];
 }
 if (aux->finished) return 0;
 else if (str) aux->p = str - 1, aux->finished = 0;
 if (aux->sep < 0) {
  for (p = start = aux->p + 1; *p; ++p)
   if (aux->tab[*p>>6]>>(*p&0x3f)&1) break;
 } else {
  for (p = start = aux->p + 1; *p; ++p)
   if (*p == aux->sep) break;
 }
 aux->p = p;
 if (*p == 0) aux->finished = 1;
 return (char *)start;
}

variable_types:
str
char *

variable_types:
sep
char *

variable_types: struct ks_tokaux_t { unsigned long tab[4]; int sep; char *p; } *

variable_types:
p
char *

variable_types:
start
char *


original_code:
int ksplit_core(char *s, int delimiter, int *_max, int **_offsets)
{
 int i, n, max, last_char, last_start, *offsets, l;
 n = 0; max = *_max; offsets = *_offsets;
 l = strlen(s);
 for (i = 0, last_char = last_start = 0; i <= l; ++i) {
  if (delimiter == 0) {
   if (((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISspace) || s[i] == 0) {
    if (((*__ctype_b_loc ())[(int) ((last_char))] & (unsigned short int) _ISgraph)) do { if (_offsets) { s[i] = 0; if (n == max) { max = max? max<<1 : 2; offsets = (int*)realloc(offsets, sizeof(int) * max); } offsets[n++] = last_start; } else ++n; } while (0);
   } else {
    if (((*__ctype_b_loc ())[(int) ((last_char))] & (unsigned short int) _ISspace) || last_char == 0) last_start = i;
   }
  } else {
   if (s[i] == delimiter || s[i] == 0) {
    if (last_char != 0 && last_char != delimiter) do { if (_offsets) { s[i] = 0; if (n == max) { max = max? max<<1 : 2; offsets = (int*)realloc(offsets, sizeof(int) * max); } offsets[n++] = last_start; } else ++n; } while (0);
   } else {
    if (last_char == delimiter || last_char == 0) last_start = i;
   }
  }
  last_char = s[i];
 }
 *_max = max; *_offsets = offsets;
 return n;
}

canonical_original_code:
int ksplit_core(char *s, int delimiter, int *_max, int **_offsets)
{
 int i; int n; int max; int last_char; int last_start; int *offsets; int l;
 n = 0; max = *_max; offsets = *_offsets;
 l = strlen(s);
 for (i = 0, last_char = last_start = 0; i <= l; ++i) {
  if (delimiter == 0) {
   if (((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISspace) || s[i] == 0) {
    if (((*__ctype_b_loc ())[(int) ((last_char))] & (unsigned short) _ISgraph)) do { if (_offsets) { s[i] = 0; if (n == max) { max = max? max<<1 : 2; offsets = (int *)realloc(offsets, sizeof(int) * max); } offsets[n++] = last_start; } else ++n; } while (0);
   } else {
    if (((*__ctype_b_loc ())[(int) ((last_char))] & (unsigned short) _ISspace) || last_char == 0) last_start = i;
   }
  } else {
   if (s[i] == delimiter || s[i] == 0) {
    if (last_char != 0 && last_char != delimiter) do { if (_offsets) { s[i] = 0; if (n == max) { max = max? max<<1 : 2; offsets = (int *)realloc(offsets, sizeof(int) * max); } offsets[n++] = last_start; } else ++n; } while (0);
   } else {
    if (last_char == delimiter || last_char == 0) last_start = i;
   }
  }
  last_char = s[i];
 }
 *_max = max; *_offsets = offsets;
 return n;
}

variable_types:
s
char *

variable_types: delimiter int

variable_types: i int

variable_types: n int

variable_types: max int

variable_types:
offsets
int *

variable_types: l int