decompiled_code:
__int64 __fastcall fd_scandir(__int64 a1, __int64 a2)
{
char *v2; // rax
__int64 v3; // rbx
_WORD *v4; // rax
__int64 v5; // r14
char v6; // al
int v7; // er15
_BYTE *v8; // r15
size_t v9; // rax
_BYTE *v10; // rax
_QWORD *v12; // r15
__int64 v13; // rcx
_BYTE *v14; // rax
__int64 v15; // [rsp+18h] [rbp-18448h]
__int64 v16; // [rsp+20h] [rbp-18440h]
__int64 v17[128]; // [rsp+28h] [rbp-18438h]
__int128 v18; // [rsp+428h] [rbp-18038h] BYREF
char s[32752]; // [rsp+438h] [rbp-18028h] BYREF
char dest[32768]; // [rsp+8428h] [rbp-10038h] BYREF
char v21[32824]; // [rsp+10428h] [rbp-8038h] BYREF

v18 = 0LL;
memset(s, 0, sizeof(s));
strcpy(dest, *(const char **)a1);
v2 = get_current_dir_name();
strcpy(v21, v2);
if ( chdir(*(const char **)a1) < 0 )
{
LABEL_19:
perror("chdir");
return 0xFFFFFFFFLL;
}
LODWORD(v3) = 0;
v4 = calloc(1uLL, 0x218uLL);
*v4 = 46;
v5 = (__int64)v4;
LOBYTE(v18) = 46;
v17[0] = (__int64)&v18 + 1;
create_dest_dir(a1, &v18);
while ( 1 )
{
(*(void (__fastcall **)(__int128 *))(a1 + 48))(&v18);
v6 = anakin_filewalker(a1, v5, *(char **)(v5 + 512), (__int64)dest, (char *)&v18, a2, *(_QWORD *)(a1 + 40));
if ( v6 )
break;
v12 = *(_QWORD **)(v5 + 520);
v13 = *(_QWORD *)(v5 + 528);
if ( !v12 )
{
LABEL_8:
printf("Total %d files\n \t\rUpdated %d files\n \t\rFailed on %d files\n", FilesFound, FilesUpdated, FilesFailed);
chdir(v21);
return 0LL;
}
v3 = (int)v3;
while ( 1 )
{
v12[64] = v13;
if ( v13 )
break;
free((void *)v5);
if ( !v12[65] )
goto LABEL_8;
if ( chdir("..") < 0 )
goto LABEL_19;
v14 = (_BYTE *)*(&v16 + v3);
v5 = (__int64)v12;
--v3;
*v14 = 0;
v13 = v12[66];
if ( !v12[65] )
goto LABEL_8;
v12 = (_QWORD *)v12[65];
}
HIDWORD(v16) = v3;
v15 = v13;
free((void *)v5);
if ( chdir("..") < 0 )
goto LABEL_19;
v7 = HIDWORD(v16) - 1;
v5 = v15;
*(_BYTE *)v17[HIDWORD(v16) - 1] = 0;
LABEL_6:
if ( chdir((const char *)v5) < 0 )
{
perror("chdir");
puts((const char *)v5);
return 0xFFFFFFFFLL;
}
LODWORD(v3) = v7 + 1;
v8 = (_BYTE *)v17[v7];
*v8 = 47;
v9 = strlen((const char *)v5);
memcpy(v8 + 1, (const void *)v5, v9);
v10 = &v8[strlen((const char *)v5) + 1];
*v10 = 0;
v17[(int)v3] = (__int64)v10;
create_dest_dir(a1, &v18);
if ( !*(_QWORD *)(v5 + 520) )
goto LABEL_8;
}
if ( v6 == 1 )
{
v5 = *(_QWORD *)(v5 + 512);
v7 = v3;
goto LABEL_6;
}
return 0xFFFFFFFFLL;
}

original_code:
int fd_scandir(struct frontdown_config *config, long long timestamp){
 char pathstring[16384*2]={0};
 char *dirpointer[128];
 int dirptrc=0;
 char ret;
 struct dirnode *node, *root, *freewilli;
 char sourcepath[16384*2];
 strcpy(sourcepath, config->source);
 char orig_dir[16384*2];
 strcpy(orig_dir, get_current_dir_name());
 if(chdir(config->source)<0){
  perror("chdir");
  return -1;
 }
 root=calloc(1,sizeof(struct dirnode));
 strcpy(root->path, ".");
 pathstring[0]='.';
 dirpointer[dirptrc]=&pathstring[1];
 create_dest_dir(config, pathstring);
 node=root;
 do{
  config->info(pathstring);
  if((ret=anakin_filewalker(config, node, node->sub, sourcepath, pathstring, timestamp, config->excludes))==0){
   next_dir:
    freewilli=node;
    node=node->next;
    if(freewilli->top==((void *)0)) break;
    freewilli->top->sub=node;
    if(node==((void *)0)){
     node=freewilli->top;
     free(freewilli);
     if(node->top==((void *)0))break;
     if(chdir("..")<0){
      perror("chdir");
      return -1;
     }
     dirptrc--;
     *dirpointer[dirptrc]='\0';
   goto next_dir;
    }
   free(freewilli);
   if(chdir("..")<0){
    perror("chdir");
    return -1;
   }
   dirptrc--;
   *dirpointer[dirptrc]='\0';
  } else if(ret==1) {
   node=node->sub;
  } else {
   return -1;
  }
  if(chdir(node->path)<0){
   perror("chdir");
   puts(node->path);
   return -1;
  }
  dirptrc++;
  *dirpointer[dirptrc-1]='/';
  memcpy(dirpointer[dirptrc-1]+1, node->path, strlen(node->path));
  dirpointer[dirptrc]=dirpointer[dirptrc-1]+1+strlen(node->path);
  *dirpointer[dirptrc]='\0';
 create_dest_dir(config, pathstring);
 }while(node->top!=((void *)0));
 printf("Total %d files\n 	\rUpdated %d files\n 	\rFailed on %d files\n", FilesFound, FilesUpdated, FilesFailed);
 chdir(orig_dir);
 return 0;
}

canonical_original_code:
int fd_scandir(struct frontdown_config *config, long long timestamp){
 char pathstring[-1] = {0};
 char *dirpointer[128];
 int dirptrc = 0;
 char ret;
 struct dirnode *node; struct dirnode *root; struct dirnode *freewilli;
 char sourcepath[-1];
 strcpy(sourcepath, config->source);
 char orig_dir[-1];
 strcpy(orig_dir, get_current_dir_name());
 if(chdir(config->source)<0){
  perror("chdir");
  return -1;
 }
 root=calloc(1,sizeof(struct dirnode));
 strcpy(root->path, ".");
 pathstring[0]='.';
 dirpointer[dirptrc]=&pathstring[1];
 create_dest_dir(config, pathstring);
 node=root;
 do{
  config->info(pathstring);
  if((ret=anakin_filewalker(config, node, node->sub, sourcepath, pathstring, timestamp, config->excludes))==0){
   next_dir:
    freewilli=node;
    node=node->next;
    if(freewilli->top==((void *)0)) break;
    freewilli->top->sub=node;
    if(node==((void *)0)){
     node=freewilli->top;
     free(freewilli);
     if(node->top==((void *)0))break;
     if(chdir("..")<0){
      perror("chdir");
      return -1;
     }
     dirptrc--;
     *dirpointer[dirptrc]='\0';
   goto next_dir;
    }
   free(freewilli);
   if(chdir("..")<0){
    perror("chdir");
    return -1;
   }
   dirptrc--;
   *dirpointer[dirptrc]='\0';
  } else if(ret==1) {
   node=node->sub;
  } else {
   return -1;
  }
  if(chdir(node->path)<0){
   perror("chdir");
   puts(node->path);
   return -1;
  }
  dirptrc++;
  *dirpointer[dirptrc-1]='/';
  memcpy(dirpointer[dirptrc-1]+1, node->path, strlen(node->path));
  dirpointer[dirptrc]=dirpointer[dirptrc-1]+1+strlen(node->path);
  *dirpointer[dirptrc]='\0';
 create_dest_dir(config, pathstring);
 }while(node->top!=((void *)0));
 printf("Total %d files\n 	\rUpdated %d files\n 	\rFailed on %d files\n", FilesFound, FilesUpdated, FilesFailed);
 chdir(orig_dir);
 return 0;
}

variable_types: struct frontdown_config { char *source; char *destination; char *destinationUname; char *destinationPwd; enum frontdown_connection_type { _DICT_=0, _FILE_=1, _FTP_=2, _HTTP_=3, _IMAP_=4, _LDAP_=5, _POP3_=6, _RTMP_=7, _RTSP_=8, _SCP_=9, _SFTP_=10, _SMTP_=11, _TELNET_=12, _TFTP_=13, _UNKNOWN_=14 } con_type; struct frontdown_exclude_list { char exclude_path[16384]; struct frontdown_exclude_list *next; } *excludes; int (*info)(char *); int (*error)(enum frontdown_error_code { _INDEX_DB_ERROR_=0, _MKDIR_ERROR_=1, _DST_CONNECTION_ERROR_=2, _PUT_FILE_ERROR_=3 }, char, char *); char last_backup; char verbose; long long now; } *

variable_types:
timestamp
long long

variable_types:
pathstring
char [-1]

variable_types:
dirpointer
char *[128]

variable_types: dirptrc int

variable_types: struct dirnode { char path[512]; struct dirnode *sub; struct dirnode *top; struct dirnode *next; } *

variable_types:
sourcepath
char [-1]


repo: pentix/frontdown

decompiled_code:
__int64 parse_config()
{
const char *v0; // rax
const char *v1; // rbp
size_t v2; // rax
const char *v3; // rax
const char *v4; // rbp
size_t v5; // rax
const char *v6; // rdi
__int64 result; // rax

search_init(&conf);
v0 = (const char *)search_for_key("source", 0LL);
if ( v0
&& (v1 = v0,
v2 = strlen(v0),
memcpy(config, v1, v2 + 1),
v3 = (const char *)search_for_key("destination", 0LL),
(v4 = v3) != 0LL) )
{
v5 = strlen(v3);
memcpy(*(&config + 1), v4, v5 + 1);
v6 = (const char *)search_for_key("lastbackup", 0LL);
if ( v6 )
*((_BYTE *)&config + 64) = atoi(v6);
search_destroy(v6);
result = 1LL;
}
else
{
((void (*)(void))search_destroy)();
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
const char *v0; // rax
const char *v1; // rbp
size_t v2; // rax
const char *v3; // rax
const char *v4; // rbp
size_t v5; // rax
const char *v6; // rdi
__int64 result; // rax

search_init(&conf);
v0 = (const char *)search_for_key("source", 0LL);
if ( v0
&& (v1 = v0,
v2 = strlen(v0),
memcpy(config, v1, v2 + 1),
v3 = (const char *)search_for_key("destination", 0LL),
(v4 = v3) != 0LL) )
{
v5 = strlen(v3);
memcpy(*(&config + 1), v4, v5 + 1);
v6 = (const char *)search_for_key("lastbackup", 0LL);
if ( v6 )
*((_BYTE *)&config + 64) = atoi(v6);
search_destroy(v6);
result = 1LL;
}
else
{
((void (*)(void))search_destroy)();
result = 0LL;
}
return result;
}

original_code:
int parse_config(void){
 search_init(conf);
 char *test_ptr;
 test_ptr = search_for_key("source", 0);
 if(test_ptr == ((void *)0)){
  search_destroy();
  return 0;
 }
 memcpy(config.source, test_ptr, strlen(test_ptr)+1);
 test_ptr = search_for_key("destination", 0);
 if(test_ptr == ((void *)0)){
  search_destroy();
  return 0;
 }
 memcpy(config.destination, test_ptr, strlen(test_ptr)+1);
 test_ptr = search_for_key("lastbackup", 0);
 if(test_ptr != ((void *)0)){
  config.last_backup = atoi(test_ptr);
 }
 search_destroy();
 return 1;
}

canonical_original_code:
int parse_config(){
 search_init(conf);
 char *test_ptr;
 test_ptr = search_for_key("source", 0);
 if(test_ptr == ((void *)0)){
  search_destroy();
  return 0;
 }
 memcpy(config.source, test_ptr, strlen(test_ptr)+1);
 test_ptr = search_for_key("destination", 0);
 if(test_ptr == ((void *)0)){
  search_destroy();
  return 0;
 }
 memcpy(config.destination, test_ptr, strlen(test_ptr)+1);
 test_ptr = search_for_key("lastbackup", 0);
 if(test_ptr != ((void *)0)){
  config.last_backup = atoi(test_ptr);
 }
 search_destroy();
 return 1;
}

return_type: int


decompiled_code:
__int64 __fastcall parse_options(int argc, char **argv)
{
char v2; // r15
char v3; // r14
char v4; // r13
int v5; // eax
__int64 v6; // rdx
__int64 v7; // rcx
unsigned int v8; // er8
char *v10; // [rsp+8h] [rbp-190h]
int v11; // [rsp+8h] [rbp-190h]
int longind; // [rsp+1Ch] [rbp-17Ch] BYREF
struct option longopts[11]; // [rsp+20h] [rbp-178h] BYREF

v2 = 0;
v3 = 0;
v4 = 0;
*((_BYTE *)&config + 64) = 0;
longind = 0;
destinationLogin = 0;
qmemcpy(longopts, &off_4520, 0x140uLL);
while ( 1 )
{
v5 = getopt_long(argc, argv, "s:d:t:hc:e:liuv", longopts, &longind);
if ( v5 == -1 )
break;
switch ( v5 )
{
case 's':
if ( v4 )
{
fwrite("Cannot use more than 1 source directory at the moment\n", 1uLL, 0x36uLL, stderr);
return (unsigned int)-1;
}
v4 = 1;
strncpy(config, optarg, 0x3FFFuLL);
break;
case 'd':
if ( v3 )
{
fwrite("Cannot use more than 1 destination directory at the moment\n", 1uLL, 0x3BuLL, stderr);
return (unsigned int)-1;
}
v3 = 1;
strncpy(*(&config + 1), optarg, 0x3FFFuLL);
break;
case 'l':
destinationLogin = 1;
break;
case 'h':
help((unsigned int)argc, argv, v6, v7, 104LL);
exit(0);
case 'c':
if ( v2 )
{
fwrite("Only 1 configuration file is allowed\n", 1uLL, 0x25uLL, stderr);
return (unsigned int)-1;
}
strncpy(conf, optarg, 0x3FFFuLL);
if ( !(unsigned int)parse_config() )
{
fwrite("Error parsing configuration file\n", 1uLL, 0x21uLL, stderr);
return (unsigned int)-1;
}
v2 = 1;
break;
case 'e':
strncpy(latest_exclude, optarg, 0x3FFFuLL);
v10 = latest_exclude;
latest_exclude = (char *)calloc(1uLL, 0x4008uLL);
*((_QWORD *)v10 + 2048) = latest_exclude;
break;
case 'i':
*((_BYTE *)&config + 64) = 1;
break;
case 'v':
*((_BYTE *)&config + 65) = 1;
break;
default:
return (unsigned int)-1;
}
}
if ( !v2 && (unsigned __int8)v3 ^ 1 | (unsigned __int8)v4 ^ 1 )
{
fwrite("Need configuration file or source and destination\n", 1uLL, 0x32uLL, stderr);
v8 = -1;
}
else if ( optind < argc )
{
v11 = v5;
fprintf(stderr, "Unkown argument: %s\n", argv[optind]);
v8 = v11;
}
else
{
v8 = 0;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv)
{
char v2; // r15
char v3; // r14
char v4; // r13
int v5; // eax
__int64 v6; // rdx
__int64 v7; // rcx
unsigned int v8; // er8
char *v10; // [rsp+8h] [rbp-190h]
int v11; // [rsp+8h] [rbp-190h]
int longind; // [rsp+1Ch] [rbp-17Ch] BYREF
struct option longopts[11]; // [rsp+20h] [rbp-178h] BYREF

v2 = 0;
v3 = 0;
v4 = 0;
*((_BYTE *)&config + 64) = 0;
longind = 0;
destinationLogin = 0;
qmemcpy(longopts, &off_4520, 0x140uLL);
while ( 1 )
{
v5 = getopt_long(argc, argv, "s:d:t:hc:e:liuv", longopts, &longind);
if ( v5 == -1 )
break;
switch ( v5 )
{
case 's':
if ( v4 )
{
fwrite("Cannot use more than 1 source directory at the moment\n", 1uLL, 0x36uLL, stderr);
return (unsigned int)-1;
}
v4 = 1;
strncpy(config, optarg, 0x3FFFuLL);
break;
case 'd':
if ( v3 )
{
fwrite("Cannot use more than 1 destination directory at the moment\n", 1uLL, 0x3BuLL, stderr);
return (unsigned int)-1;
}
v3 = 1;
strncpy(*(&config + 1), optarg, 0x3FFFuLL);
break;
case 'l':
destinationLogin = 1;
break;
case 'h':
help((unsigned int)argc, argv, v6, v7, 104LL);
exit(0);
case 'c':
if ( v2 )
{
fwrite("Only 1 configuration file is allowed\n", 1uLL, 0x25uLL, stderr);
return (unsigned int)-1;
}
strncpy(conf, optarg, 0x3FFFuLL);
if ( !(unsigned int)parse_config() )
{
fwrite("Error parsing configuration file\n", 1uLL, 0x21uLL, stderr);
return (unsigned int)-1;
}
v2 = 1;
break;
case 'e':
strncpy(latest_exclude, optarg, 0x3FFFuLL);
v10 = latest_exclude;
latest_exclude = (char *)calloc(1uLL, 0x4008uLL);
*((_QWORD *)v10 + 2048) = latest_exclude;
break;
case 'i':
*((_BYTE *)&config + 64) = 1;
break;
case 'v':
*((_BYTE *)&config + 65) = 1;
break;
default:
return (unsigned int)-1;
}
}
if ( !v2 && (unsigned __int8)v3 ^ 1 | (unsigned __int8)v4 ^ 1 )
{
fwrite("Need configuration file or source and destination\n", 1uLL, 0x32uLL, stderr);
v8 = -1;
}
else if ( optind < argc )
{
v11 = v5;
fprintf(stderr, "Unkown argument: %s\n", argv[optind]);
v8 = v11;
}
else
{
v8 = 0;
}
return v8;
}

original_code:
int parse_options(int argc, char **argv){
 struct option command_options[] = {
  {"source", 1, 0, 's'},
  {"destination", 1, 0, 'd'},
  {"help", 0, 0, 'h'},
  {"conf", 1, 0, 'c'},
  {"exclude", 1, 0, 'e'},
  {"login", 0, 0, 'l'},
  {"gui", 0, 0, 'u'},
  {"incremental", 0, 0, 'i'},
  {"verbose", 0, 0, 'v'},
  {0, 0, 0, 0}
 };
 int opt, option_index=0;
 config.last_backup = 0;
 destinationLogin = 0;
 char s=0, d=0, c=0;
 while(1){
  opt = getopt_long(argc, argv, "s:d:t:hc:e:liuv", command_options, &option_index);
  if(opt == -1)
   break;
  if(opt == 's'){
   if(s){
    fprintf(stderr, "Cannot use more than 1 source directory at the moment\n");
    return(-1);
   }
   strncpy(config.source, optarg, 16383);
   s=1;
  } else if(opt == 'd'){
   if(d){
    fprintf(stderr, "Cannot use more than 1 destination directory at the moment\n");
    return(-1);
   }
   strncpy(config.destination, optarg, 16383);
   d=1;
  } else if(opt == 'l'){
   destinationLogin = 1;
  } else if(opt == 'h'){
   help();
   exit(0);
  } else if(opt == 'c'){
   if(c){
    fprintf(stderr, "Only 1 configuration file is allowed\n");
    return(-1);
   }
   strncpy(conf, optarg, 16383);
   if(!parse_config()){
    fprintf(stderr, "Error parsing configuration file\n");
    return(-1);
   }
   c=1;
  } else if(opt == 'e'){
   strncpy(latest_exclude->exclude_path, optarg, 16383);
   latest_exclude->next = calloc(1, sizeof(struct frontdown_exclude_list));
   latest_exclude = latest_exclude->next;
  } else if(opt == 'i'){
   config.last_backup=1;
  } else if(opt == 'v'){
   config.verbose=1;
  } else{
   return(-1);
  }
 }
 if(!(c || (s && d))){
  fprintf(stderr, "Need configuration file or source and destination\n");
  return(-1);
 }
 if(optind < argc){
  fprintf(stderr, "Unkown argument: %s\n", argv[optind]);
  return(-1);
 }
 return(0);
}

canonical_original_code:
int parse_options(int argc, char **argv){
 struct option command_options[] = {
  {"source", 1, 0, 's'},
  {"destination", 1, 0, 'd'},
  {"help", 0, 0, 'h'},
  {"conf", 1, 0, 'c'},
  {"exclude", 1, 0, 'e'},
  {"login", 0, 0, 'l'},
  {"gui", 0, 0, 'u'},
  {"incremental", 0, 0, 'i'},
  {"verbose", 0, 0, 'v'},
  {0, 0, 0, 0}
 };
 int opt; int option_index = 0;
 config.last_backup = 0;
 destinationLogin = 0;
 char s = 0; char d = 0; char c = 0;
 while(1){
  opt = getopt_long(argc, argv, "s:d:t:hc:e:liuv", command_options, &option_index);
  if(opt == -1)
   break;
  if(opt == 's'){
   if(s){
    fprintf(stderr, "Cannot use more than 1 source directory at the moment\n");
    return(-1);
   }
   strncpy(config.source, optarg, 16383);
   s=1;
  } else if(opt == 'd'){
   if(d){
    fprintf(stderr, "Cannot use more than 1 destination directory at the moment\n");
    return(-1);
   }
   strncpy(config.destination, optarg, 16383);
   d=1;
  } else if(opt == 'l'){
   destinationLogin = 1;
  } else if(opt == 'h'){
   help();
   exit(0);
  } else if(opt == 'c'){
   if(c){
    fprintf(stderr, "Only 1 configuration file is allowed\n");
    return(-1);
   }
   strncpy(conf, optarg, 16383);
   if(!parse_config()){
    fprintf(stderr, "Error parsing configuration file\n");
    return(-1);
   }
   c=1;
  } else if(opt == 'e'){
   strncpy(latest_exclude->exclude_path, optarg, 16383);
   latest_exclude->next = calloc(1, sizeof(struct frontdown_exclude_list));
   latest_exclude = latest_exclude->next;
  } else if(opt == 'i'){
   config.last_backup=1;
  } else if(opt == 'v'){
   config.verbose=1;
  } else{
   return(-1);
  }
 }
 if(!(c || (s && d))){
  fprintf(stderr, "Need configuration file or source and destination\n");
  return(-1);
 }
 if(optind < argc){
  fprintf(stderr, "Unkown argument: %s\n", argv[optind]);
  return(-1);
 }
 return(0);
}

variable_types: argc int

variable_types:
argv
char **

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

variable_types: opt int

variable_types: s char

variable_types: d char

variable_types: c char

user_defined_types: struct frontdown_exclude_list { char exclude_path[16384]; struct frontdown_exclude_list *next; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // r12
__int64 v9; // rax
__int64 v10; // r13
__int64 v11; // rdi
__int64 v12; // r14
__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; // rbp
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // r12
__int64 v9; // rax
__int64 v10; // r13
__int64 v11; // rdi
__int64 v12; // r14
__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;
}

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


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:
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)
{
int v2; // ebp
int i; // ebx
char *v5; // r12
int v6; // esi
char *v7; // rax
int v8; // edx
__int64 result; // rax

v2 = a2 / 2;
if ( a2 > 1 )
{
for ( i = a2; i > 1; v2 = i / 2 )
{
v5 = a1;
v6 = i - 1;
a1 += 4 * v2;
v7 = &v5[4 * i - 4];
v8 = *(_DWORD *)a1;
i = i - v2 - 1;
*(_DWORD *)a1 = *(_DWORD *)v7;
*(_DWORD *)v7 = v8;
qsort(v5, v6, 4uLL, (__compar_fn_t)ord);
result = quickV(v5, (unsigned int)v2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1, int a2)
{
int v2; // ebp
int i; // ebx
char *v5; // r12
int v6; // esi
char *v7; // rax
int v8; // edx
__int64 result; // rax

v2 = a2 / 2;
if ( a2 > 1 )
{
for ( i = a2; i > 1; v2 = i / 2 )
{
v5 = a1;
v6 = i - 1;
a1 += 4 * v2;
v7 = &v5[4 * i - 4];
v8 = *(_DWORD *)a1;
i = i - v2 - 1;
*(_DWORD *)a1 = *(_DWORD *)v7;
*(_DWORD *)v7 = v8;
qsort(v5, v6, 4uLL, (__compar_fn_t)ord);
result = func9(v5, (unsigned int)v2);
}
}
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; // eax
size_t v4; // r13
int v5; // ebx
int v6; // er12
_DWORD *v7; // rbp
unsigned int v8; // eax
_DWORD *v9; // r15
__int64 v10; // rbx
__int64 v11; // rsi
_DWORD *v13; // rax
int v14; // edi
_DWORD *v15; // rax
_DWORD *v16; // rdx
__int64 v17; // rdi
int v18; // eax
_DWORD *v19; // rsi
__int64 v20; // rdx
size_t v21; // r13
_DWORD *v22; // rcx
int v23; // edi
int v24; // edi
char v25; // [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]);
v4 = v3;
v5 = 10000;
v6 = v3;
v25 = *argv[2];
v7 = malloc(4LL * v3);
v8 = time(0LL);
srand(v8);
if ( (int)v4 >= 10000 )
v5 = v4;
if ( (int)v4 > 0 )
{
v9 = v7;
do
*v9++ = rand() % v5;
while ( v9 != &v7[(unsigned int)(v4 - 1) + 1] );
switch ( v25 )
{
case 'a':
goto LABEL_10;
case 'i':
goto LABEL_13;
case 'm':
goto LABEL_17;
case 'o':
goto LABEL_25;
case 'r':
goto LABEL_26;
case 't':
goto LABEL_27;
default:
goto LABEL_8;
}
}
switch ( v25 )
{
case 'a':
goto LABEL_12;
case 'i':
LABEL_13:
if ( (int)v4 <= 1 )
goto LABEL_9;
v13 = v7 + 1;
do
*v13++ = *v7;
while ( v13 != &v7[(unsigned int)(v4 - 2) + 2] );
goto LABEL_10;
case 'm':
LABEL_17:
v14 = 1;
if ( (int)v4 <= 1 )
goto LABEL_9;
do
{
v15 = v7;
v16 = &v7[v14];
do
{
*v16 = *v15 + 1;
*v15++ *= 2;
*v16++ *= 2;
}
while ( v15 != &v7[v14 - 1 + 1] );
v14 *= 2;
}
while ( (int)v4 > v14 );
v17 = (int)v4 / 2;
v18 = (int)v4 / 4;
if ( (int)v4 <= 3 )
goto LABEL_9;
v19 = &v7[v17];
v20 = 0LL;
v21 = v4 - v17;
v22 = v19;
do
{
v23 = v7[v20];
v7[v20] = *(v22 - 1);
*(v22 - 1) = v23;
v24 = v19[v20];
v19[v20++] = v22[v21 - 1];
v22[v21 - 1] = v24;
--v22;
}
while ( v18 > (int)v20 );
goto LABEL_10;
case 'o':
LABEL_25:
qsort(v7, v4, 4uLL, ord);
goto LABEL_9;
case 'r':
LABEL_26:
qsort(v7, v4, 4uLL, rev);
goto LABEL_9;
case 't':
LABEL_27:
qsort(v7, v4, 4uLL, ord);
quickV(v7, (unsigned int)v4);
goto LABEL_9;
default:
LABEL_8:
puts("ERRO!!!");
LABEL_9:
if ( (int)v4 > 0 )
{
LABEL_10:
v10 = 0LL;
do
{
v11 = (unsigned int)v7[v10++];
printf(", %d", v11);
}
while ( v6 > (int)v10 );
}
LABEL_12:
free(v7);
free(0LL);
putchar(10);
return 0;
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
size_t v4; // r13
int v5; // ebx
int v6; // er12
_DWORD *v7; // rbp
unsigned int v8; // eax
_DWORD *v9; // r15
__int64 v10; // rbx
__int64 v11; // rsi
_DWORD *v13; // rax
int v14; // edi
_DWORD *v15; // rax
_DWORD *v16; // rdx
__int64 v17; // rdi
int v18; // eax
_DWORD *v19; // rsi
__int64 v20; // rdx
size_t v21; // r13
_DWORD *v22; // rcx
int v23; // edi
int v24; // edi
char v25; // [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]);
v4 = v3;
v5 = 10000;
v6 = v3;
v25 = *argv[2];
v7 = malloc(4LL * v3);
v8 = time(0LL);
srand(v8);
if ( (int)v4 >= 10000 )
v5 = v4;
if ( (int)v4 > 0 )
{
v9 = v7;
do
*v9++ = rand() % v5;
while ( v9 != &v7[(unsigned int)(v4 - 1) + 1] );
switch ( v25 )
{
case 'a':
goto LABEL_10;
case 'i':
goto LABEL_13;
case 'm':
goto LABEL_17;
case 'o':
goto LABEL_25;
case 'r':
goto LABEL_26;
case 't':
goto LABEL_27;
default:
goto LABEL_8;
}
}
switch ( v25 )
{
case 'a':
goto LABEL_12;
case 'i':
LABEL_13:
if ( (int)v4 <= 1 )
goto LABEL_9;
v13 = v7 + 1;
do
*v13++ = *v7;
while ( v13 != &v7[(unsigned int)(v4 - 2) + 2] );
goto LABEL_10;
case 'm':
LABEL_17:
v14 = 1;
if ( (int)v4 <= 1 )
goto LABEL_9;
do
{
v15 = v7;
v16 = &v7[v14];
do
{
*v16 = *v15 + 1;
*v15++ *= 2;
*v16++ *= 2;
}
while ( v15 != &v7[v14 - 1 + 1] );
v14 *= 2;
}
while ( (int)v4 > v14 );
v17 = (int)v4 / 2;
v18 = (int)v4 / 4;
if ( (int)v4 <= 3 )
goto LABEL_9;
v19 = &v7[v17];
v20 = 0LL;
v21 = v4 - v17;
v22 = v19;
do
{
v23 = v7[v20];
v7[v20] = *(v22 - 1);
*(v22 - 1) = v23;
v24 = v19[v20];
v19[v20++] = v22[v21 - 1];
v22[v21 - 1] = v24;
--v22;
}
while ( v18 > (int)v20 );
goto LABEL_10;
case 'o':
LABEL_25:
qsort(v7, v4, 4uLL, ord);
goto LABEL_9;
case 'r':
LABEL_26:
qsort(v7, v4, 4uLL, rev);
goto LABEL_9;
case 't':
LABEL_27:
qsort(v7, v4, 4uLL, ord);
func9(v7, (unsigned int)v4);
goto LABEL_9;
default:
LABEL_8:
puts("ERRO!!!");
LABEL_9:
if ( (int)v4 > 0 )
{
LABEL_10:
v10 = 0LL;
do
{
v11 = (unsigned int)v7[v10++];
printf(", %d", v11);
}
while ( v6 > (int)v10 );
}
LABEL_12:
free(v7);
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: argc int

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(void *dest, int a2)
{
if ( a2 > 1 )
{
mergeSort(dest);
mergeSort((char *)dest + 4 * (a2 >> 1));
mergeS(dest, a2);
}
}

canonical_decompiled_code:
void __fastcall func8(void *dest, int a2)
{
if ( a2 > 1 )
{
func8(dest);
func8((char *)dest + 4 * (a2 >> 1));
func7(dest, 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);
    }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
void *v4; // rax
void *v5; // r13
int v6; // ebx
int v8; // [rsp+Ch] [rbp-2Ch]

__isoc99_scanf();
v3 = malloc(4LL * v8);
v4 = malloc(4LL * v8);
if ( !v3 || (v5 = v4) == 0LL )
{
puts("Malloc falhou!");
exit(1);
}
v6 = 5000;
read(v4, (unsigned int)v8);
do
{
if ( v8 > 0 )
memcpy(v3, v5, 4LL * v8);
mergeSort(v3);
--v6;
}
while ( v6 );
free(v5);
free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
void *v4; // rax
void *v5; // r13
int v6; // ebx
int v8; // [rsp+Ch] [rbp-2Ch]

__isoc99_scanf();
v3 = malloc(4LL * v8);
v4 = malloc(4LL * v8);
if ( !v3 || (v5 = v4) == 0LL )
{
puts("Malloc falhou!");
exit(1);
}
v6 = 5000;
func9(v4, (unsigned int)v8);
do
{
if ( v8 > 0 )
memcpy(v3, v5, 4LL * v8);
func8(v3);
--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:
argv
char **

variable_types:
b
int *


read

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

if ( a2 > 0 )
{
v2 = a1;
do
{
v2 += 4LL;
result = __isoc99_scanf();
}
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
{
v2 += 4LL;
result = __isoc99_scanf();
}
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]);
}


insertionSort

decompiled_code:
void __fastcall insertionSort(_DWORD *a1, int a2)
{
__int64 v2; // rbp
int v3; // er12
_DWORD *v4; // rbx
int v5; // eax

if ( a2 > 1 )
{
v2 = 1LL;
LABEL_3:
while ( 2 )
{
v3 = a1[v2];
v4 = a1;
v5 = 0;
while ( v3 >= *v4 )
{
++v5;
++v4;
if ( v5 == (_DWORD)v2 )
{
if ( ++v2 != a2 )
goto LABEL_3;
return;
}
}
if ( v5 < (int)v2 )
memmove(
(char *)a1 + 4 * v2 - 4LL * (unsigned int)(v2 - v5 - 1),
(char *)a1 + 4 * v2 - 4LL * (unsigned int)(v2 - v5 - 1) - 4,
4LL * (unsigned int)(v2 - v5 - 1) + 4);
++v2;
*v4 = v3;
if ( v2 != a2 )
continue;
break;
}
}
}

canonical_decompiled_code:
void __fastcall func8(_DWORD *a1, int a2)
{
__int64 v2; // rbp
int v3; // er12
_DWORD *v4; // rbx
int v5; // eax

if ( a2 > 1 )
{
v2 = 1LL;
LABEL_3:
while ( 2 )
{
v3 = a1[v2];
v4 = a1;
v5 = 0;
while ( v3 >= *v4 )
{
++v5;
++v4;
if ( v5 == (_DWORD)v2 )
{
if ( ++v2 != a2 )
goto LABEL_3;
return;
}
}
if ( v5 < (int)v2 )
memmove(
(char *)a1 + 4 * v2 - 4LL * (unsigned int)(v2 - v5 - 1),
(char *)a1 + 4 * v2 - 4LL * (unsigned int)(v2 - v5 - 1) - 4,
4LL * (unsigned int)(v2 - v5 - 1) + 4);
++v2;
*v4 = v3;
if ( v2 != a2 )
continue;
break;
}
}
}

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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
void *v4; // rax
void *v5; // r13
int v6; // ebp
int v8; // [rsp+Ch] [rbp-2Ch]

__isoc99_scanf();
v3 = malloc(4LL * v8);
v4 = malloc(4LL * v8);
if ( !v3 || (v5 = v4) == 0LL )
{
puts("Malloc falhou!");
exit(1);
}
v6 = 5000;
read(v4, (unsigned int)v8);
do
{
if ( v8 > 0 )
memcpy(v3, v5, 4LL * v8);
quickSort(v3, 0LL, (unsigned int)(v8 - 1));
--v6;
}
while ( v6 );
free(v3);
free(v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
void *v4; // rax
void *v5; // r13
int v6; // ebp
int v8; // [rsp+Ch] [rbp-2Ch]

__isoc99_scanf();
v3 = malloc(4LL * v8);
v4 = malloc(4LL * v8);
if ( !v3 || (v5 = v4) == 0LL )
{
puts("Malloc falhou!");
exit(1);
}
v6 = 5000;
func10(v4, (unsigned int)v8);
do
{
if ( v8 > 0 )
memcpy(v3, v5, 4LL * v8);
func9(v3, 0LL, (unsigned int)(v8 - 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;
}

variable_types:
a
int *


partit

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, int a3)
{
int v4; // ebp
int i; // esi
int v6; // ebx

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

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2, int a3)
{
int v4; // ebp
int i; // esi
int v6; // ebx

v4 = a2;
for ( i = a3 - a2; i > 5; i = a3 - (v6 + 1) )
{
v6 = func7(a1, v4, a3);
func9(a1, (unsigned int)v4, (unsigned int)(v6 - 1));
v4 = v6 + 1;
}
if ( a3 > v4 )
func8((_DWORD *)(a1 + 4LL * v4), i + 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
{
v2 += 4LL;
result = __isoc99_scanf();
}
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)
{
__int64 v2; // rbp
unsigned int *v3; // rbx
__int64 v4; // rsi

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

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

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


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


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


read

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

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

variable_types:
a
int *

variable_types: n int


repo: perezdidac/portscan

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

strcpy(v2, ".\n");
v1 = _mm_load_si128((const __m128i *)&LC0);
v0 = strlen(v1.m128i_i8);
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
__m128i v1; // [rsp+0h] [rbp-108h] BYREF
char v2[8]; // [rsp+10h] [rbp-F8h] BYREF

strcpy(v2, ".\n");
v1 = _mm_load_si128((const __m128i *)&LC0);
v0 = strlen(v1.m128i_i8);
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 *v3; // r13
int v5; // eax
char *v6; // rax
__int64 result; // rax

v3 = (char *)(a3 + 16);
*(_QWORD *)(a3 + 272) = 0x3E8FFFF00010008LL;
*(_QWORD *)a3 = -1LL;
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(v3, optarg);
*(_DWORD *)a3 = 0;
break;
case 'e':
*(_WORD *)(a3 + 276) = atoi(optarg);
break;
case 'h':
ps_show_help();
return result;
case 'l':
v6 = optarg;
*(_DWORD *)(a3 + 4) = 0;
*(_QWORD *)(a3 + 8) = v6;
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 *v3; // r13
int v5; // eax
char *v6; // rax
__int64 result; // rax

v3 = (char *)(a3 + 16);
*(_QWORD *)(a3 + 272) = 0x3E8FFFF00010008LL;
*(_QWORD *)a3 = -1LL;
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(v3, optarg);
*(_DWORD *)a3 = 0;
break;
case 'e':
*(_WORD *)(a3 + 276) = atoi(optarg);
break;
case 'h':
func1();
return result;
case 'l':
v6 = optarg;
*(_DWORD *)(a3 + 4) = 0;
*(_QWORD *)(a3 + 8) = v6;
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 *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // r14
int v4; // ebx
int v5; // ebx
int v6; // er13
signed __int64 v7; // rbx
void *v8; // rsp
int *v9; // rbx
unsigned int i; // er12
__pid_t v11; // eax
bool v12; // zf
int v13; // edi
__pid_t v14; // eax
int j; // er12
int *v16; // r12
__int64 v17; // rbx
int v18; // edi
int k; // ebx
_BYTE *v20; // r14
int v21; // edi
int v22; // er14
size_t v23; // rax
size_t v24; // rax
size_t v25; // rax
void *v27; // rsp
_BYTE v28[4]; // [rsp+0h] [rbp-290h] BYREF
_BYTE v29[12]; // [rsp+4h] [rbp-28Ch] BYREF
int fd; // [rsp+10h] [rbp-280h]
unsigned __int16 v31; // [rsp+16h] [rbp-27Ah]
char *cp; // [rsp+18h] [rbp-278h]
_BYTE *v33; // [rsp+20h] [rbp-270h]
in_addr_t v34; // [rsp+28h] [rbp-268h]
int v35; // [rsp+2Ch] [rbp-264h]
unsigned int buf; // [rsp+38h] [rbp-258h] BYREF
unsigned __int16 v37; // [rsp+3Ch] [rbp-254h]
char s[256]; // [rsp+40h] [rbp-250h] BYREF
int v39; // [rsp+140h] [rbp-150h] BYREF
int v40; // [rsp+144h] [rbp-14Ch]
char *file; // [rsp+148h] [rbp-148h]
char v42; // [rsp+150h] [rbp-140h] BYREF
unsigned __int16 v43; // [rsp+250h] [rbp-40h]
unsigned __int16 v44; // [rsp+252h] [rbp-3Eh]
unsigned __int16 v45; // [rsp+254h] [rbp-3Ch]
unsigned __int16 v46; // [rsp+256h] [rbp-3Ah]

ps_parse_options(argc, (char **)argv, (__int64)&v39);
if ( !v40 )
{
fd = open(file, 577);
if ( fd < 0 )
ps_error(0LL);
}
*(_QWORD *)&v29[4] = v28;
cp = &v42;
if ( v39 == -1 )
goto LABEL_34;
while ( 2 )
{
v34 = inet_addr(cp);
if ( v34 == -1 )
{
v34 = ps_getip(cp);
if ( v34 == -1 )
ps_error(3LL);
}
v3 = v44;
if ( !v44 )
ps_error(4LL);
v4 = v45;
if ( !v45 )
ps_error(5LL);
v31 = v46;
if ( !v46 )
ps_error(7LL);
if ( v3 > (unsigned __int16)v4 )
ps_error(6LL);
v5 = v4 - v3;
v6 = v5 + 1;
v35 = v5;
if ( v5 + 1 > v43 )
v6 = v43;
v7 = 8LL * v6;
if ( !v43 )
{
ps_error(2LL);
v27 = alloca(v7);
v33 = v28;
signal(2, (__sighandler_t)ps_cancel);
if ( v35 >= 0 )
goto LABEL_24;
goto LABEL_28;
}
v8 = alloca(v7);
v33 = v28;
if ( v6 <= 0 )
{
signal(2, (__sighandler_t)ps_cancel);
if ( v35 >= 0 )
goto LABEL_24;
goto LABEL_33;
}
v9 = (int *)v28;
for ( i = 0; i != v6; ++i )
{
if ( pipe(v9) >= 0 )
{
v11 = fork();
v12 = v11 == 0;
if ( v11 < 0 )
goto LABEL_22;
}
else
{
ps_error(8LL);
v14 = fork();
v12 = v14 == 0;
if ( v14 < 0 )
{
LABEL_22:
ps_error(9LL);
goto LABEL_19;
}
}
if ( v12 )
{
close(*(_DWORD *)&v28[8 * i + 4]);
if ( i )
{
v20 = v29;
do
{
v21 = *(_DWORD *)v20;
v20 += 8;
close(v21);
}
while ( &v28[8 * i + 4] != v20 );
}
while ( read(*(_DWORD *)&v28[8 * i], &buf, 8uLL) == 8 )
{
if ( !v40 )
{
sprintf(s, "Child %d started scanning...\n", i);
v24 = strlen(s);
write(fd, s, v24);
}
v22 = ps_scan(buf, v37, v31);
if ( !v40 )
{
sprintf(s, "Child %d finished.\n", i);
v25 = strlen(s);
write(fd, s, v25);
}
if ( v22 )
{
if ( v22 == 1 )
{
sprintf(s, "%s %d SUCCESS\n", cp, v37);
}
else if ( v22 == 2 )
{
sprintf(s, "%s %d TIMEOUT\n", cp, v37);
}
}
else
{
sprintf(s, "%s %d ERROR\n", cp, v37);
}
v23 = strlen(s);
write(1, s, v23);
}
close(*(_DWORD *)&v28[8 * i]);
return 0;
}
LABEL_19:
v13 = *v9;
v9 += 2;
close(v13);
}
signal(2, (__sighandler_t)ps_cancel);
if ( v35 < 0 )
goto LABEL_29;
LABEL_24:
for ( j = 0; j <= v35; ++j )
{
buf = v34;
v37 = v3 + j;
if ( write(*(_DWORD *)&v33[8 * (j % v6) + 4], &buf, 8uLL) != 8 )
ps_error(13LL);
}
LABEL_28:
if ( v6 > 0 )
{
LABEL_29:
v16 = (int *)(v33 + 4);
v17 = (__int64)&v33[8 * (v6 - 1) + 12];
do
{
v18 = *v16;
v16 += 2;
close(v18);
}
while ( v16 != (int *)v17 );
for ( k = 0; k != v6; ++k )
wait(0LL);
}
LABEL_33:
signal(2, 0LL);
if ( v39 == -1 )
{
LABEL_34:
if ( (unsigned int)_isoc99_scanf("%s", cp) == -1 )
break;
continue;
}
break;
}
if ( !v40 )
close(fd);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // r14
int v4; // ebx
int v5; // ebx
int v6; // er13
signed __int64 v7; // rbx
void *v8; // rsp
int *v9; // rbx
unsigned int i; // er12
__pid_t v11; // eax
bool v12; // zf
int v13; // edi
__pid_t v14; // eax
int j; // er12
int *v16; // r12
__int64 v17; // rbx
int v18; // edi
int k; // ebx
_BYTE *v20; // r14
int v21; // edi
int v22; // er14
size_t v23; // rax
size_t v24; // rax
size_t v25; // rax
void *v27; // rsp
_BYTE v28[4]; // [rsp+0h] [rbp-290h] BYREF
_BYTE v29[12]; // [rsp+4h] [rbp-28Ch] BYREF
int fd; // [rsp+10h] [rbp-280h]
unsigned __int16 v31; // [rsp+16h] [rbp-27Ah]
char *cp; // [rsp+18h] [rbp-278h]
_BYTE *v33; // [rsp+20h] [rbp-270h]
in_addr_t v34; // [rsp+28h] [rbp-268h]
int v35; // [rsp+2Ch] [rbp-264h]
unsigned int buf; // [rsp+38h] [rbp-258h] BYREF
unsigned __int16 v37; // [rsp+3Ch] [rbp-254h]
char s[256]; // [rsp+40h] [rbp-250h] BYREF
int v39; // [rsp+140h] [rbp-150h] BYREF
int v40; // [rsp+144h] [rbp-14Ch]
char *file; // [rsp+148h] [rbp-148h]
char v42; // [rsp+150h] [rbp-140h] BYREF
unsigned __int16 v43; // [rsp+250h] [rbp-40h]
unsigned __int16 v44; // [rsp+252h] [rbp-3Eh]
unsigned __int16 v45; // [rsp+254h] [rbp-3Ch]
unsigned __int16 v46; // [rsp+256h] [rbp-3Ah]

func3(argc, (char **)argv, (__int64)&v39);
if ( !v40 )
{
fd = open(file, 577);
if ( fd < 0 )
ps_error(0LL);
}
*(_QWORD *)&v29[4] = v28;
cp = &v42;
if ( v39 == -1 )
goto LABEL_34;
while ( 2 )
{
v34 = inet_addr(cp);
if ( v34 == -1 )
{
v34 = ps_getip(cp);
if ( v34 == -1 )
ps_error(3LL);
}
v3 = v44;
if ( !v44 )
ps_error(4LL);
v4 = v45;
if ( !v45 )
ps_error(5LL);
v31 = v46;
if ( !v46 )
ps_error(7LL);
if ( v3 > (unsigned __int16)v4 )
ps_error(6LL);
v5 = v4 - v3;
v6 = v5 + 1;
v35 = v5;
if ( v5 + 1 > v43 )
v6 = v43;
v7 = 8LL * v6;
if ( !v43 )
{
ps_error(2LL);
v27 = alloca(v7);
v33 = v28;
signal(2, (__sighandler_t)ps_cancel);
if ( v35 >= 0 )
goto LABEL_24;
goto LABEL_28;
}
v8 = alloca(v7);
v33 = v28;
if ( v6 <= 0 )
{
signal(2, (__sighandler_t)ps_cancel);
if ( v35 >= 0 )
goto LABEL_24;
goto LABEL_33;
}
v9 = (int *)v28;
for ( i = 0; i != v6; ++i )
{
if ( pipe(v9) >= 0 )
{
v11 = fork();
v12 = v11 == 0;
if ( v11 < 0 )
goto LABEL_22;
}
else
{
ps_error(8LL);
v14 = fork();
v12 = v14 == 0;
if ( v14 < 0 )
{
LABEL_22:
ps_error(9LL);
goto LABEL_19;
}
}
if ( v12 )
{
close(*(_DWORD *)&v28[8 * i + 4]);
if ( i )
{
v20 = v29;
do
{
v21 = *(_DWORD *)v20;
v20 += 8;
close(v21);
}
while ( &v28[8 * i + 4] != v20 );
}
while ( read(*(_DWORD *)&v28[8 * i], &buf, 8uLL) == 8 )
{
if ( !v40 )
{
sprintf(s, "Child %d started scanning...\n", i);
v24 = strlen(s);
write(fd, s, v24);
}
v22 = ps_scan(buf, v37, v31);
if ( !v40 )
{
sprintf(s, "Child %d finished.\n", i);
v25 = strlen(s);
write(fd, s, v25);
}
if ( v22 )
{
if ( v22 == 1 )
{
sprintf(s, "%s %d SUCCESS\n", cp, v37);
}
else if ( v22 == 2 )
{
sprintf(s, "%s %d TIMEOUT\n", cp, v37);
}
}
else
{
sprintf(s, "%s %d ERROR\n", cp, v37);
}
v23 = strlen(s);
write(1, s, v23);
}
close(*(_DWORD *)&v28[8 * i]);
return 0;
}
LABEL_19:
v13 = *v9;
v9 += 2;
close(v13);
}
signal(2, (__sighandler_t)ps_cancel);
if ( v35 < 0 )
goto LABEL_29;
LABEL_24:
for ( j = 0; j <= v35; ++j )
{
buf = v34;
v37 = v3 + j;
if ( write(*(_DWORD *)&v33[8 * (j % v6) + 4], &buf, 8uLL) != 8 )
ps_error(13LL);
}
LABEL_28:
if ( v6 > 0 )
{
LABEL_29:
v16 = (int *)(v33 + 4);
v17 = (__int64)&v33[8 * (v6 - 1) + 12];
do
{
v18 = *v16;
v16 += 2;
close(v18);
}
while ( v16 != (int *)v17 );
for ( k = 0; k != v6; ++k )
wait(0LL);
}
LABEL_33:
signal(2, 0LL);
if ( v39 == -1 )
{
LABEL_34:
if ( (unsigned int)_isoc99_scanf("%s", cp) == -1 )
break;
continue;
}
break;
}
if ( !v40 )
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
in_addr_t result; // eax
char v3[24]; // [rsp+0h] [rbp-18h] BYREF

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

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

v1 = gethostbyname(a1);
if ( v1 && (unsigned int)inet_ntop(2, *(const void **)v1->h_addr_list, v3, 0x10u) )
result = inet_addr(v3);
else
result = -1;
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; // eax
int v5; // ebp
unsigned int v6; // er12
socklen_t v7; // edx
int v9; // eax
socklen_t optlen; // [rsp+8h] [rbp-D0h] BYREF
int optval; // [rsp+Ch] [rbp-CCh] BYREF
struct sockaddr v12; // [rsp+10h] [rbp-C8h] BYREF
struct timeval timeout; // [rsp+20h] [rbp-B8h] BYREF
fd_set writefds; // [rsp+30h] [rbp-A8h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int16 a2, unsigned __int16 a3)
{
int v4; // eax
int v5; // ebp
unsigned int v6; // er12
socklen_t v7; // edx
int v9; // eax
socklen_t optlen; // [rsp+8h] [rbp-D0h] BYREF
int optval; // [rsp+Ch] [rbp-CCh] BYREF
struct sockaddr v12; // [rsp+10h] [rbp-C8h] BYREF
struct timeval timeout; // [rsp+20h] [rbp-B8h] BYREF
fd_set writefds; // [rsp+30h] [rbp-A8h] BYREF

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

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
const char *v4; // rsi
__int64 v5; // rcx
_DWORD *v6; // rdi
size_t v7; // rax
size_t v8; // rax
const char *v9; // rsi
__int64 v10; // rcx
_DWORD *v11; // rdi
size_t v12; // rax
const char *v13; // rsi
__int64 v14; // rcx
_DWORD *v15; // rdi
size_t v16; // rax
size_t v17; // rax
size_t v18; // rax
size_t v19; // rax
size_t v20; // rax
size_t v21; // rax
size_t v22; // rax
_OWORD v23[16]; // [rsp+0h] [rbp-108h] BYREF

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

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

switch ( a1 )
{
case 0:
strcpy((char *)&v23[2], "e.\n");
v23[0] = _mm_load_si128((const __m128i *)&LC11);
v23[1] = _mm_load_si128((const __m128i *)&LC12);
goto LABEL_3;
case 1:
strcpy((char *)&v23[2], "function.\n");
v23[0] = _mm_load_si128((const __m128i *)&LC13);
v23[1] = _mm_load_si128((const __m128i *)&LC14);
LABEL_3:
v1 = strlen((const char *)v23);
write(2, v23, v1);
break;
case 2:
strcpy((char *)v23, "Incorrect number of max childs.\n");
v22 = strlen((const char *)v23);
write(2, v23, v22);
exit(2);
case 3:
strcpy((char *)v23, "Incorrect host address.\n");
v21 = strlen((const char *)v23);
write(2, v23, v21);
exit(2);
case 4:
strcpy((char *)v23, "Incorrect start port.\n");
v20 = strlen((const char *)v23);
write(2, v23, v20);
exit(2);
case 5:
strcpy((char *)v23, "Incorrect final port.\n");
v19 = strlen((const char *)v23);
write(2, v23, v19);
exit(2);
case 6:
strcpy((char *)v23, "Initial port must be equal or higher than final port.\n");
v18 = strlen((const char *)v23);
write(2, v23, v18);
exit(2);
case 7:
strcpy((char *)&v23[1], "t.\n");
v23[0] = _mm_load_si128((const __m128i *)&LC15);
v17 = strlen((const char *)v23);
write(2, v23, v17);
exit(2);
case 8:
v13 = "Error while executing pipe() function.\n";
v14 = 10LL;
v15 = v23;
while ( v14 )
{
*v15 = *(_DWORD *)v13;
v13 += 4;
++v15;
--v14;
}
v16 = strlen((const char *)v23);
write(2, v23, v16);
exit(2);
case 9:
v9 = "Error while executing fork() function.\n";
v10 = 10LL;
v11 = v23;
while ( v10 )
{
*v11 = *(_DWORD *)v9;
v9 += 4;
++v11;
--v10;
}
v12 = strlen((const char *)v23);
write(2, v23, v12);
exit(2);
case 10:
strcpy((char *)v23, "Error while executing socket() function.\n");
v8 = strlen((const char *)v23);
write(2, v23, v8);
exit(2);
case 11:
v4 = "Cannot set the unblocking socket mode.\n";
v5 = 10LL;
v6 = v23;
while ( v5 )
{
*v6 = *(_DWORD *)v4;
v4 += 4;
++v6;
--v5;
}
v7 = strlen((const char *)v23);
write(2, v23, v7);
exit(2);
case 12:
strcpy((char *)v23, "Error while executing read() to read from the pipe.\n");
v3 = strlen((const char *)v23);
write(2, v23, v3);
exit(2);
case 13:
strcpy((char *)v23, "Error while executing write() to write to the pipe.\n");
v2 = strlen((const char *)v23);
write(2, v23, v2);
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 __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
_DWORD *v4; // rbp
__int64 v5; // rsi

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

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

v3 = 0LL;
v4 = malloc(4uLL);
do
{
printf("Old %i: %x\n", (unsigned int)v3, (unsigned int)v4[v3]);
v5 = (unsigned int)v3;
v4[v3++] = 269488144;
printf("New %i: %x\n", v5, 269488144LL);
}
while ( v3 != 4 );
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 *


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


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(unsigned int a1)
{
return _byteswap_ulong(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return _byteswap_ulong(a1);
}

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(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

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