decompiled_code:
__int64 __fastcall db_open(int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax

switch ( a1 )
{
case 1:
result = qdbm_open(a2, a3);
break;
case 2:
result = bdb_open(a2, a3);
break;
case 3:
result = tc_open(a2, a3);
break;
case 4:
result = xtdb_open(a2, a3);
break;
case 5:
result = xleveldb_open(a2, a3);
break;
case 6:
result = null_open(a2, a3);
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax

switch ( a1 )
{
case 1:
result = qdbm_open(a2, a3);
break;
case 2:
result = bdb_open(a2, a3);
break;
case 3:
result = tc_open(a2, a3);
break;
case 4:
result = xtdb_open(a2, a3);
break;
case 5:
result = xleveldb_open(a2, a3);
break;
case 6:
result = null_open(a2, a3);
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
struct db_conn *db_open(enum backend_type type, const char *name, int flags)
{
 switch (type) {
 case BE_QDBM:
  return qdbm_open(name, flags);
 case BE_BDB:
  return bdb_open(name, flags);
 case BE_TC:
  return tc_open(name, flags);
 case BE_TDB:
  return xtdb_open(name, flags);
 case BE_LEVELDB:
  return xleveldb_open(name, flags);
 case BE_NULL:
  return null_open(name, flags);
 default:
  return ((void *)0);
 }
}

canonical_original_code:
struct db_conn *db_open(enum backend_type type, char *name, int flags)
{
 switch (type) {
 case BE_QDBM:
  return qdbm_open(name, flags);
 case BE_BDB:
  return bdb_open(name, flags);
 case BE_TC:
  return tc_open(name, flags);
 case BE_TDB:
  return xtdb_open(name, flags);
 case BE_LEVELDB:
  return xleveldb_open(name, flags);
 case BE_NULL:
  return null_open(name, flags);
 default:
  return ((void *)0);
 }
}

variable_types: enum backend_type { BE_UNKNOWN=-2, BE_UNSUPPORTED=-1, BE_QDBM=1, BE_BDB=2, BE_TC=3, BE_TDB=4, BE_LEVELDB=5, BE_NULL=6 }

variable_types:
name
char *

variable_types: flags int


repo: dolfly/nmdb

decompiled_code:
__int64 __fastcall be_type_from_str(__int64 a1)
{
unsigned int v1; // er8

if ( !strcmp((const char *)a1, "qdbm") )
return (unsigned int)-1;
v1 = 2;
if ( !strcmp((const char *)a1, "bdb") )
return v1;
if ( *(_BYTE *)a1 != 116 || *(_BYTE *)(a1 + 1) != 99 || *(_BYTE *)(a1 + 2) )
{
v1 = 4;
if ( strcmp((const char *)a1, "tdb") )
{
v1 = 5;
if ( strcmp((const char *)a1, "leveldb") )
v1 = strcmp((const char *)a1, "null") == 0 ? 6 : -2;
}
return v1;
}
return 3LL;
}

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

if ( !strcmp((const char *)a1, "qdbm") )
return (unsigned int)-1;
v1 = 2;
if ( !strcmp((const char *)a1, "bdb") )
return v1;
if ( *(_BYTE *)a1 != 116 || *(_BYTE *)(a1 + 1) != 99 || *(_BYTE *)(a1 + 2) )
{
v1 = 4;
if ( strcmp((const char *)a1, "tdb") )
{
v1 = 5;
if ( strcmp((const char *)a1, "leveldb") )
v1 = strcmp((const char *)a1, "null") == 0 ? 6 : -2;
}
return v1;
}
return 3LL;
}

original_code:
enum backend_type be_type_from_str(const char *name)
{
 if (strcmp(name, "qdbm") == 0)
  return 0 ? BE_QDBM : BE_UNSUPPORTED;
 if (strcmp(name, "bdb") == 0)
  return 1 ? BE_BDB : BE_UNSUPPORTED;
 if (strcmp(name, "tc") == 0)
  return 1 ? BE_TC : BE_UNSUPPORTED;
 if (strcmp(name, "tdb") == 0)
  return 1 ? BE_TDB : BE_UNSUPPORTED;
 if (strcmp(name, "leveldb") == 0)
  return 1 ? BE_LEVELDB : BE_UNSUPPORTED;
 if (strcmp(name, "null") == 0)
  return 1 ? BE_NULL : BE_UNSUPPORTED;
 return BE_UNKNOWN;
}

canonical_original_code:
enum backend_type be_type_from_str(char *name)
{
 if (strcmp(name, "qdbm") == 0)
  return 0 ? BE_QDBM : BE_UNSUPPORTED;
 if (strcmp(name, "bdb") == 0)
  return 1 ? BE_BDB : BE_UNSUPPORTED;
 if (strcmp(name, "tc") == 0)
  return 1 ? BE_TC : BE_UNSUPPORTED;
 if (strcmp(name, "tdb") == 0)
  return 1 ? BE_TDB : BE_UNSUPPORTED;
 if (strcmp(name, "leveldb") == 0)
  return 1 ? BE_LEVELDB : BE_UNSUPPORTED;
 if (strcmp(name, "null") == 0)
  return 1 ? BE_NULL : BE_UNSUPPORTED;
 return BE_UNKNOWN;
}

return_type: enum backend_type { BE_UNKNOWN=-2, BE_UNSUPPORTED=-1, BE_QDBM=1, BE_BDB=2, BE_TC=3, BE_TDB=4, BE_LEVELDB=5, BE_NULL=6 }


decompiled_code:
const char *__fastcall be_str_from_type(int a1)
{
const char *result; // rax

result = "qdbm";
if ( a1 != 1 )
{
result = "bdb";
if ( a1 != 2 )
{
result = "tc";
if ( a1 != 3 )
{
result = "tdb";
if ( a1 != 4 )
{
result = "leveldb";
if ( a1 != 5 )
{
result = "unknown";
if ( a1 == 6 )
result = "null";
}
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(int a1)
{
const char *result; // rax

result = "qdbm";
if ( a1 != 1 )
{
result = "bdb";
if ( a1 != 2 )
{
result = "tc";
if ( a1 != 3 )
{
result = "tdb";
if ( a1 != 4 )
{
result = "leveldb";
if ( a1 != 5 )
{
result = "unknown";
if ( a1 == 6 )
result = "null";
}
}
}
}
}
return result;
}

original_code:
const char *be_str_from_type(enum backend_type type)
{
 if (type == BE_QDBM)
  return "qdbm";
 if (type == BE_BDB)
  return "bdb";
 if (type == BE_TC)
  return "tc";
 if (type == BE_TDB)
  return "tdb";
 if (type == BE_LEVELDB)
  return "leveldb";
 if (type == BE_NULL)
  return "null";
 return "unknown";
}

return_type: char *

user_defined_types: enum backend_type { BE_UNKNOWN=-2, BE_UNSUPPORTED=-1, BE_QDBM=1, BE_BDB=2, BE_TC=3, BE_TDB=4, BE_LEVELDB=5, BE_NULL=6 }


decompiled_code:
__int64 __fastcall xleveldb_close(void *ptr)
{
leveldb_close(*(_QWORD *)ptr);
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
leveldb_close(*(_QWORD *)ptr);
free(ptr);
return 1LL;
}

original_code:
int xleveldb_close(struct db_conn *db)
{
 leveldb_close(db->conn);
 free(db);
 return 1;
}

variable_types: struct db_conn { void *conn; int (*set)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long vsize); int (*get)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long *vsize); int (*del)(struct db_conn *db, unsigned char *key, unsigned long ksize); int (*firstkey)(struct db_conn *db, unsigned char *key, unsigned long *ksize); int (*nextkey)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *nextkey, unsigned long *nksize); int (*close)(struct db_conn *db); } *

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
int v4; // eax
int result; // eax
int v6; // eax

nmdb_init();
if ( argc <= 2 )
goto LABEL_8;
v3 = argv[1];
if ( !strcmp("tipc", v3) )
{
atoi(argv[2]);
v4 = nmdb_add_tipc_server();
}
else
{
if ( argc != 4 )
goto LABEL_8;
if ( !strcmp("tcp", argv[1]) )
{
atoi(argv[3]);
v4 = nmdb_add_tcp_server();
}
else
{
if ( strcmp("udp", v3) )
{
if ( !strcmp("sctp", v3) )
{
atoi(argv[3]);
v4 = nmdb_add_sctp_server();
goto LABEL_10;
}
LABEL_8:
help();
return 1;
}
atoi(argv[3]);
v4 = nmdb_add_udp_server();
}
}
LABEL_10:
if ( v4 )
{
v6 = nmdb_stats();
if ( v6 <= 0 )
{
printf("Error %d\n", (unsigned int)v6);
result = 1;
}
else
{
nmdb_free();
result = 0;
}
}
else
{
perror("Error adding server");
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
int v4; // eax
int result; // eax
int v6; // eax

nmdb_init();
if ( argc <= 2 )
goto LABEL_8;
v3 = argv[1];
if ( !strcmp("tipc", v3) )
{
atoi(argv[2]);
v4 = nmdb_add_tipc_server();
}
else
{
if ( argc != 4 )
goto LABEL_8;
if ( !strcmp("tcp", argv[1]) )
{
atoi(argv[3]);
v4 = nmdb_add_tcp_server();
}
else
{
if ( strcmp("udp", v3) )
{
if ( !strcmp("sctp", v3) )
{
atoi(argv[3]);
v4 = nmdb_add_sctp_server();
goto LABEL_10;
}
LABEL_8:
func7();
return 1;
}
atoi(argv[3]);
v4 = nmdb_add_udp_server();
}
}
LABEL_10:
if ( v4 )
{
v6 = nmdb_stats();
if ( v6 <= 0 )
{
printf("Error %d\n", (unsigned int)v6);
result = 1;
}
else
{
nmdb_free();
result = 0;
}
}
else
{
perror("Error adding server");
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 struct cache *cd;
 struct queue *q;
 struct db_conn *db;
 pid_t pid;
 pthread_t *dbthread;
 if (!load_settings(argc, argv))
  return 1;
 if (!log_init()) {
  perror("Error opening log file");
  return 1;
 }
 stats_init(&stats);
 cd = cache_create(settings.numobjs, 0);
 if (cd == ((void *)0)) {
  errlog("Error creating cache");
  return 1;
 }
 cache_table = cd;
 q = queue_create();
 if (q == ((void *)0)) {
  errlog("Error creating queue");
  return 1;
 }
 op_queue = q;
 db = db_open(settings.backend, settings.dbname, 0);
 if (db == ((void *)0)) {
  errlog("Error opening DB");
  return 1;
 }
 wlog("Opened database \"%s\" with %s backend\n", settings.dbname,
  be_str_from_type(settings.backend));
 if (!settings.foreground) {
  pid = fork();
  if (pid > 0) {
   return 0;
  } else if (pid < 0) {
   errlog("Error in fork()");
   return 1;
  }
  close(0);
  setsid();
 }
 wlog("Starting nmdb\n");
 write_pid();
 dbthread = db_loop_start(db);
 net_loop();
 db_loop_stop(dbthread);
 db->close(db);
 queue_free(q);
 cache_free(cd);
 if (settings.pidfile)
  unlink(settings.pidfile);
 free_settings();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct cache *cd;
 struct queue *q;
 struct db_conn *db;
 int pid;
 unsigned long *dbthread;
 if (!load_settings(argc, argv))
  return 1;
 if (!log_init()) {
  perror("Error opening log file");
  return 1;
 }
 stats_init(&stats);
 cd = cache_create(settings.numobjs, 0);
 if (cd == ((void *)0)) {
  errlog("Error creating cache");
  return 1;
 }
 cache_table = cd;
 q = queue_create();
 if (q == ((void *)0)) {
  errlog("Error creating queue");
  return 1;
 }
 op_queue = q;
 db = db_open(settings.backend, settings.dbname, 0);
 if (db == ((void *)0)) {
  errlog("Error opening DB");
  return 1;
 }
 wlog("Opened database \"%s\" with %s backend\n", settings.dbname,
  be_str_from_type(settings.backend));
 if (!settings.foreground) {
  pid = fork();
  if (pid > 0) {
   return 0;
  } else if (pid < 0) {
   errlog("Error in fork()");
   return 1;
  }
  close(0);
  setsid();
 }
 wlog("Starting nmdb\n");
 write_pid();
 dbthread = db_loop_start(db);
 net_loop();
 db_loop_stop(dbthread);
 db->close(db);
 queue_free(q);
 cache_free(cd);
 if (settings.pidfile)
  unlink(settings.pidfile);
 free_settings();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct cache { unsigned long numobjs; unsigned int flags; unsigned long hashlen; struct cache_chain { unsigned long len; struct cache_entry { unsigned char *key; unsigned char *val; unsigned long ksize; unsigned long vsize; struct cache_entry *prev; struct cache_entry *next; } entries[4]; struct cache_entry *first; struct cache_entry *last; } *table; } *

variable_types: struct queue { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; unsigned long size; struct queue_entry { unsigned int operation; struct req_info { int fd; int type; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *clisa; unsigned int clilen; unsigned int id; unsigned short cmd; unsigned short flags; unsigned char *payload; unsigned long psize; void (*reply_mini)(struct req_info *req, unsigned int reply); void (*reply_err)(struct req_info *req, unsigned int reply); void (*reply_long)(struct req_info *req, unsigned int reply, unsigned char *val, unsigned long vsize); } *req; unsigned char *key; unsigned char *val; unsigned char *newval; unsigned long ksize; unsigned long vsize; unsigned long nvsize; struct queue_entry *prev; } *top; } *

variable_types: pid int

variable_types:
dbthread
unsigned long *

user_defined_types: struct cache { unsigned long numobjs; unsigned int flags; unsigned long hashlen; struct cache_chain *table; }

user_defined_types: struct queue { union pthread_mutex_t lock; union pthread_cond_t cond; unsigned long size; struct queue_entry *top; }

user_defined_types: struct db_conn { void *conn; int (*set)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long vsize); int (*get)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *val, unsigned long *vsize); int (*del)(struct db_conn *db, unsigned char *key, unsigned long ksize); int (*firstkey)(struct db_conn *db, unsigned char *key, unsigned long *ksize); int (*nextkey)(struct db_conn *db, unsigned char *key, unsigned long ksize, unsigned char *nextkey, unsigned long *nksize); int (*close)(struct db_conn *db); }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct cache_chain { unsigned long len; struct cache_entry entries[4]; struct cache_entry *first; struct cache_entry *last; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct queue_entry { unsigned int operation; struct req_info *req; unsigned char *key; unsigned char *val; unsigned char *newval; unsigned long ksize; unsigned long vsize; unsigned long nvsize; struct queue_entry *prev; }

user_defined_types: struct req_info { int fd; int type; struct sockaddr *clisa; unsigned int clilen; unsigned int id; unsigned short cmd; unsigned short flags; unsigned char *payload; unsigned long psize; void (*reply_mini)(struct req_info *req, unsigned int reply); void (*reply_err)(struct req_info *req, unsigned int reply); void (*reply_long)(struct req_info *req, unsigned int reply, unsigned char *val, unsigned long vsize); }


help

decompiled_code:
int help()
{
return puts("Use: nmdb-stats [ tipc port | [tcp|udp|sctp] host port ]");
}

canonical_decompiled_code:
int func7()
{
return puts("Use: nmdb-stats [ tipc port | [tcp|udp|sctp] host port ]");
}

original_code:
static void help(void) {
 char h[] = "nmdb [options]\n"
   "\n"
   "  -b backend	backend to use (" "tdb" ")\n"
   "  -d dbpath	database path ('database' by default)\n"
   "  -l lower	TIPC lower port number (10)\n"
   "  -L upper	TIPC upper port number (= lower)\n"
   "  -t port	TCP listening port (26010)\n"
   "  -T addr	TCP listening address (all local addresses)\n"
   "  -u port	UDP listening port (26010)\n"
   "  -U addr	UDP listening address (all local addresses)\n"
   "  -s port	SCTP listening port (26010)\n"
   "  -S addr	SCTP listening address (all local addresses)\n"
   "  -c nobj	max. number of objects to be cached, in thousands (128)\n"
   "  -o fname	log to the given file (stdout).\n"
   "  -i pidfile file to write the PID to (none).\n"
   "  -f		don't fork and stay in the foreground\n"
   "  -p		enable passive mode, for redundancy purposes (read docs.)\n"
   "  -r		read-only mode\n"
   "  -h		show this help\n"
   "\n"
   "Available backends: " "" "bdb " "tc " "tdb " "leveldb " "null " "\n"
   "\n"
   "Please report bugs to Alberto Bertogli (albertito@blitiri.com.ar)\n"
   "\n";
 printf("%s", h);
}

canonical_original_code:
static void help() {
 char h[] = "nmdb [options]\n"
   "\n"
   "  -b backend	backend to use (" "tdb" ")\n"
   "  -d dbpath	database path ('database' by default)\n"
   "  -l lower	TIPC lower port number (10)\n"
   "  -L upper	TIPC upper port number (= lower)\n"
   "  -t port	TCP listening port (26010)\n"
   "  -T addr	TCP listening address (all local addresses)\n"
   "  -u port	UDP listening port (26010)\n"
   "  -U addr	UDP listening address (all local addresses)\n"
   "  -s port	SCTP listening port (26010)\n"
   "  -S addr	SCTP listening address (all local addresses)\n"
   "  -c nobj	max. number of objects to be cached, in thousands (128)\n"
   "  -o fname	log to the given file (stdout).\n"
   "  -i pidfile file to write the PID to (none).\n"
   "  -f		don't fork and stay in the foreground\n"
   "  -p		enable passive mode, for redundancy purposes (read docs.)\n"
   "  -r		read-only mode\n"
   "  -h		show this help\n"
   "\n"
   "Available backends: " "" "bdb " "tc " "tdb " "leveldb " "null " "\n"
   "\n"
   "Please report bugs to Alberto Bertogli (albertito@blitiri.com.ar)\n"
   "\n";
 printf("%s", h);
}

variable_types:
h
char []

return_type: void


repo: domroselli/echo-server

decompiled_code:
__int64 __fastcall socket_recv(int fd, void *buf, unsigned __int64 a3)
{
size_t v4; // r13
__int64 v5; // rbx
int v6; // eax
unsigned int v7; // er14

*(_BYTE *)buf = 0;
if ( fd < 0 || a3 <= 1 )
return (unsigned int)-1;
printf("\x1B[0mrecv: ");
v4 = a3 - 1;
while ( 1 )
{
v6 = recv(fd, buf, v4, 0);
v7 = v6;
if ( v6 <= 0 )
break;
v5 = v6;
printf("%s", (const char *)buf);
if ( *((char *)buf + (int)v5 - 1) == 10 )
goto LABEL_8;
}
if ( !v6 )
{
v5 = 0LL;
puts("\x1B[0;33mdisconnected");
LABEL_8:
*((_BYTE *)buf + v5) = 0;
return v7;
}
if ( v6 != -1 )
{
v5 = v6;
goto LABEL_8;
}
perror("\x1B[0;31msocket_recv");
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, void *buf, unsigned __int64 a3)
{
size_t v4; // r13
__int64 v5; // rbx
int v6; // eax
unsigned int v7; // er14

*(_BYTE *)buf = 0;
if ( fd < 0 || a3 <= 1 )
return (unsigned int)-1;
printf("\x1B[0mrecv: ");
v4 = a3 - 1;
while ( 1 )
{
v6 = recv(fd, buf, v4, 0);
v7 = v6;
if ( v6 <= 0 )
break;
v5 = v6;
printf("%s", (const char *)buf);
if ( *((char *)buf + (int)v5 - 1) == 10 )
goto LABEL_8;
}
if ( !v6 )
{
v5 = 0LL;
puts("\x1B[0;33mdisconnected");
LABEL_8:
*((_BYTE *)buf + v5) = 0;
return v7;
}
if ( v6 != -1 )
{
v5 = v6;
goto LABEL_8;
}
perror("\x1B[0;31msocket_recv");
return v7;
}

original_code:
int socket_recv(int fd, char *buf, size_t bufsize) {
    int nrecvd = 0;
    buf[nrecvd] = '\0';
    if (buf == ((void *)0) || bufsize <= 1 || fd < 0) {
        return -1;
    }
    printf("\x1B[0m" "recv: ");
    while ((nrecvd = recv( fd, buf, bufsize-1, 0)) > 0) {
        printf("%s", buf);
        if (buf[nrecvd-1] == '\n') {
            break;
        }
    }
    if (nrecvd == 0) {
        printf("\x1B[0;33m" "disconnected\n");
    }
    if (nrecvd == -1) {
        perror("\x1B[0;31m" "socket_recv");
        return -1;
    }
    buf[nrecvd] = '\0';
    return nrecvd;
}

canonical_original_code:
int socket_recv(int fd, char *buf, unsigned long bufsize) {
    int nrecvd = 0;
    buf[nrecvd] = '\0';
    if (buf == ((void *)0) || bufsize <= 1 || fd < 0) {
        return -1;
    }
    printf("\x1B[0m" "recv: ");
    while ((nrecvd = recv( fd, buf, bufsize-1, 0)) > 0) {
        printf("%s", buf);
        if (buf[nrecvd-1] == '\n') {
            break;
        }
    }
    if (nrecvd == 0) {
        printf("\x1B[0;33m" "disconnected\n");
    }
    if (nrecvd == -1) {
        perror("\x1B[0;31m" "socket_recv");
        return -1;
    }
    buf[nrecvd] = '\0';
    return nrecvd;
}

variable_types: fd int

variable_types:
buf
char *

variable_types:
bufsize
unsigned long

variable_types: nrecvd int


decompiled_code:
__int64 __fastcall socket_send(int fd, void *buf, size_t n)
{
int v4; // er12
int v5; // ebp
int v6; // eax

if ( fd < 0 )
return 0xFFFFFFFFLL;
if ( !buf )
return 0xFFFFFFFFLL;
v4 = n;
v5 = 0;
printf("\x1B[0msend: ");
if ( (int)n <= 0 )
return 0LL;
while ( 1 )
{
v6 = send(fd, buf, n, 0);
if ( v6 <= 0 )
break;
v5 += v6;
v4 -= v6;
printf("%.*s", v5, (const char *)buf);
if ( v4 <= 0 )
return 0LL;
}
if ( v6 != -1 && v6 )
return 0LL;
perror("\x1B[0;31msocket_send ");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, void *buf, size_t n)
{
int v4; // er12
int v5; // ebp
int v6; // eax

if ( fd < 0 )
return 0xFFFFFFFFLL;
if ( !buf )
return 0xFFFFFFFFLL;
v4 = n;
v5 = 0;
printf("\x1B[0msend: ");
if ( (int)n <= 0 )
return 0LL;
while ( 1 )
{
v6 = send(fd, buf, n, 0);
if ( v6 <= 0 )
break;
v5 += v6;
v4 -= v6;
printf("%.*s", v5, (const char *)buf);
if ( v4 <= 0 )
return 0LL;
}
if ( v6 != -1 && v6 )
return 0LL;
perror("\x1B[0;31msocket_send ");
return 0xFFFFFFFFLL;
}

original_code:
int socket_send(int fd, const char *buf, size_t slen) {
    int nleft, nsent, start;
    if (fd < 0 || buf == ((void *)0) || slen < 0) {
        return -1;
    }
    start = nsent = 0;
    nleft = slen;
    printf("\x1B[0m" "send: ");
    while(nleft > 0 && (nsent = send(fd, buf, slen, 0)) > 0) {
        printf( "%.*s", start+nsent, buf);
        start += nsent;
        nleft -= nsent;
    }
    if (nsent == -1 || (nsent == 0 && nleft > 0)) {
        perror("\x1B[0;31m" "socket_send ");
        return -1;
    }
    return 0;
}

canonical_original_code:
int socket_send(int fd, char *buf, unsigned long slen) {
    int nleft; int nsent; int start;
    if (fd < 0 || buf == ((void *)0) || slen < 0) {
        return -1;
    }
    start = nsent = 0;
    nleft = slen;
    printf("\x1B[0m" "send: ");
    while(nleft > 0 && (nsent = send(fd, buf, slen, 0)) > 0) {
        printf( "%.*s", start+nsent, buf);
        start += nsent;
        nleft -= nsent;
    }
    if (nsent == -1 || (nsent == 0 && nleft > 0)) {
        perror("\x1B[0;31m" "socket_send ");
        return -1;
    }
    return 0;
}

variable_types:
slen
unsigned long

variable_types: nleft int

variable_types: nsent int

variable_types: start int


decompiled_code:
__pid_t sigchld_handler()
{
__pid_t result; // eax

do
result = waitpid(-1, 0LL, 1);
while ( result > 0 );
return result;
}

canonical_decompiled_code:
__pid_t func0()
{
__pid_t result; // eax

do
result = waitpid(-1, 0LL, 1);
while ( result > 0 );
return result;
}

original_code:
void sigchld_handler(int s) {
    while (waitpid( -1, ((void *)0), 1) > 0)
        ;
}

variable_types: s int


decompiled_code:
int set_sigaction()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)sigchld_handler;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0x10000000;
return sigaction(17, &v1, 0LL);
}

canonical_decompiled_code:
int func2()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)sigchld_handler;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0x10000000;
return sigaction(17, &v1, 0LL);
}

original_code:
int set_sigaction( ) {
    struct sigaction sa;
    sa.__sigaction_handler.sa_handler = sigchld_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0x10000000;
    return sigaction(17, &sa, ((void *)0));
}

canonical_original_code:
int set_sigaction() {
    struct sigaction sa;
    sa.__sigaction_handler.sa_handler = sigchld_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0x10000000;
    return sigaction(17, &sa, ((void *)0));
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
__int64 __fastcall socket_open(__int64 a1)
{
__int64 v1; // rbx
int v2; // eax
unsigned int v3; // er12
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 1;
if ( a1 )
{
v1 = a1;
do
{
v2 = socket(*(_DWORD *)(v1 + 4), *(_DWORD *)(v1 + 8), *(_DWORD *)(v1 + 12));
v3 = v2;
if ( v2 == -1 )
{
perror("\x1B[0;33mserver: socket");
}
else if ( setsockopt(v2, 1, 2, optval, 4u) == -1 )
{
perror("\x1B[0;33msetsockopt");
}
else
{
if ( bind(v3, *(const struct sockaddr **)(v1 + 24), *(_DWORD *)(v1 + 16)) != -1 )
return v3;
perror("\x1B[0;33mserver: bind");
}
v1 = *(_QWORD *)(v1 + 40);
}
while ( v1 );
fwrite("\x1B[0;31msocket_open: failed to bind\n", 1uLL, 0x23uLL, stderr);
if ( v3 != -1 )
close(v3);
}
else
{
v3 = -1;
fwrite("\x1B[0;31msocket_open: failed to bind\n", 1uLL, 0x23uLL, stderr);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
int v2; // eax
unsigned int v3; // er12
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 1;
if ( a1 )
{
v1 = a1;
do
{
v2 = socket(*(_DWORD *)(v1 + 4), *(_DWORD *)(v1 + 8), *(_DWORD *)(v1 + 12));
v3 = v2;
if ( v2 == -1 )
{
perror("\x1B[0;33mserver: socket");
}
else if ( setsockopt(v2, 1, 2, optval, 4u) == -1 )
{
perror("\x1B[0;33msetsockopt");
}
else
{
if ( bind(v3, *(const struct sockaddr **)(v1 + 24), *(_DWORD *)(v1 + 16)) != -1 )
return v3;
perror("\x1B[0;33mserver: bind");
}
v1 = *(_QWORD *)(v1 + 40);
}
while ( v1 );
fwrite("\x1B[0;31msocket_open: failed to bind\n", 1uLL, 0x23uLL, stderr);
if ( v3 != -1 )
close(v3);
}
else
{
v3 = -1;
fwrite("\x1B[0;31msocket_open: failed to bind\n", 1uLL, 0x23uLL, stderr);
}
return v3;
}

original_code:
int socket_open(struct addrinfo *pservinfo) {
    int yes = 1;
    int fd = -1;
    struct addrinfo *p;
    for (p = pservinfo; p != ((void *)0); p = p->ai_next) {
        if ((fd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
            perror("\x1B[0;33m" "server: socket");
            continue;
        }
        if (setsockopt(fd, 1, 2, &yes, sizeof(int)) == -1) {
            perror("\x1B[0;33m" "setsockopt");
            continue;
        }
        if (bind(fd, p->ai_addr, p->ai_addrlen) == -1) {
            perror("\x1B[0;33m" "server: bind");
            continue;
        }
        break;
    }
    if (p == ((void *)0)) {
        fprintf(stderr, "\x1B[0;31m" "socket_open: failed to bind\n");
        if (fd != -1) {
            close(fd);
        }
    }
    return fd;
}

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: yes int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall socket_create(char *service)
{
int v1; // eax
int v2; // eax
unsigned int v3; // er12
const char *v5; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-38h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
pai = 0LL;
req.ai_socktype = 1;
req.ai_flags = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v1 = getaddrinfo(0LL, service, &req, &pai);
if ( v1 )
{
v3 = -1;
v5 = gai_strerror(v1);
fprintf(stderr, "\x1B[0;31mgetaddrinfo: %s\n", v5);
}
else
{
v2 = socket_open((__int64)pai);
v3 = v2;
if ( v2 != -1 && listen(v2, 10) == -1 )
{
v3 = -1;
perror("\x1B[0;31mlisten");
}
}
freeaddrinfo(pai);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *service)
{
int v1; // eax
int v2; // eax
unsigned int v3; // er12
const char *v5; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-38h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
pai = 0LL;
req.ai_socktype = 1;
req.ai_flags = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v1 = getaddrinfo(0LL, service, &req, &pai);
if ( v1 )
{
v3 = -1;
v5 = gai_strerror(v1);
fprintf(stderr, "\x1B[0;31mgetaddrinfo: %s\n", v5);
}
else
{
v2 = func3((__int64)pai);
v3 = v2;
if ( v2 != -1 && listen(v2, 10) == -1 )
{
v3 = -1;
perror("\x1B[0;31mlisten");
}
}
freeaddrinfo(pai);
return v3;
}

original_code:
int socket_create(const char *port) {
    int result;
    int fd;
    struct addrinfo hints;
    struct addrinfo *pservinfo = ((void *)0);
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0001;
    if ((result = getaddrinfo(((void *)0), port, &hints, &pservinfo)) != 0) {
        fprintf(stderr, "\x1B[0;31m" "getaddrinfo: %s\n", gai_strerror(result));
        fd = -1;
        goto error;
    }
    if ((fd = socket_open(pservinfo)) == -1) {
        fd = -1;
        goto error;
    }
    if (listen(fd, 10) == -1) {
        perror("\x1B[0;31m" "listen");
        fd = -1;
        goto error;
    }
error:
    freeaddrinfo(pservinfo);
    return fd;
}

canonical_original_code:
int socket_create(char *port) {
    int result;
    int fd;
    struct addrinfo hints;
    struct addrinfo *pservinfo = ((void *)0);
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0001;
    if ((result = getaddrinfo(((void *)0), port, &hints, &pservinfo)) != 0) {
        fprintf(stderr, "\x1B[0;31m" "getaddrinfo: %s\n", gai_strerror(result));
        fd = -1;
        goto error;
    }
    if ((fd = socket_open(pservinfo)) == -1) {
        fd = -1;
        goto error;
    }
    if (listen(fd, 10) == -1) {
        perror("\x1B[0;31m" "listen");
        fd = -1;
        goto error;
    }
error:
    freeaddrinfo(pservinfo);
    return fd;
}

variable_types:
port
char *

variable_types: result int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall incoming_socket_serv(int fd, int a2)
{
int v2; // eax
char *i; // r12
size_t v5; // rax
int v6; // ebx
int stat_loc[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( fd < 0 )
return 0xFFFFFFFFLL;
if ( a2 < 0 )
return 0xFFFFFFFFLL;
v2 = fork();
if ( !v2 )
{
close(fd);
for ( i = (char *)calloc(0x3E8uLL, 1uLL); ; socket_send((unsigned int)a2, i, v5) )
{
v6 = socket_recv((unsigned int)a2, i, 1000LL);
if ( v6 <= 0 )
break;
v5 = strlen(i);
}
close(a2);
free(i);
if ( v6 != -1 )
exit(0);
exit(1);
}
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
waitpid(v2, stat_loc, 0);
return (unsigned int)-(stat_loc[0] != 0);
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, int a2)
{
int v2; // eax
char *i; // r12
size_t v5; // rax
int v6; // ebx
int stat_loc[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( fd < 0 )
return 0xFFFFFFFFLL;
if ( a2 < 0 )
return 0xFFFFFFFFLL;
v2 = fork();
if ( !v2 )
{
close(fd);
for ( i = (char *)calloc(0x3E8uLL, 1uLL); ; socket_send((unsigned int)a2, i, v5) )
{
v6 = socket_recv((unsigned int)a2, i, 1000LL);
if ( v6 <= 0 )
break;
v5 = strlen(i);
}
close(a2);
free(i);
if ( v6 != -1 )
exit(0);
exit(1);
}
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
waitpid(v2, stat_loc, 0);
return (unsigned int)-(stat_loc[0] != 0);
}

original_code:
int incoming_socket_serv(int sfd, int afd) {
    int recvd, pid, status;
    char *buf;
    if (sfd < 0 || afd < 0) {
        return -1;
    }
    pid = fork();
    if (pid == 0) {
        close(sfd);
        buf = (char *)malloc(sizeof(char) * 1000);
        memset(buf, 0, sizeof(char) * 1000);
        while ((recvd = socket_recv(afd, buf, 1000)) > 0) {
            socket_send(afd, buf, strlen(buf));
        }
        close(afd);
        free(buf);
        if (recvd == -1) {
            exit(1);
        }
        exit(0);
    } else if (pid > 0) {
        waitpid(pid, &status, 0);
    } else {
        return -1;
    }
    if (status != 0) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int incoming_socket_serv(int sfd, int afd) {
    int recvd; int pid; int status;
    char *buf;
    if (sfd < 0 || afd < 0) {
        return -1;
    }
    pid = fork();
    if (pid == 0) {
        close(sfd);
        buf = (char *)malloc(sizeof(char) * 1000);
        memset(buf, 0, sizeof(char) * 1000);
        while ((recvd = socket_recv(afd, buf, 1000)) > 0) {
            socket_send(afd, buf, strlen(buf));
        }
        close(afd);
        free(buf);
        if (recvd == -1) {
            exit(1);
        }
        exit(0);
    } else if (pid > 0) {
        waitpid(pid, &status, 0);
    } else {
        return -1;
    }
    if (status != 0) {
        return -1;
    }
    return 0;
}

variable_types: sfd int

variable_types: afd int

variable_types: recvd int

variable_types: pid int

variable_types: status int


decompiled_code:
void __fastcall __noreturn incoming_socket_wait(int fd)
{
int v1; // ebp
_WORD *v2; // rax
socklen_t v3; // ecx
socklen_t addr_len; // [rsp+0h] [rbp-CCh] BYREF
char buf[16]; // [rsp+4h] [rbp-C8h] BYREF
__int128 v6; // [rsp+14h] [rbp-B8h]
__int64 v7; // [rsp+24h] [rbp-A8h]
int v8; // [rsp+2Ch] [rbp-A0h]
__int16 v9; // [rsp+30h] [rbp-9Ch]
struct sockaddr addr; // [rsp+34h] [rbp-98h] BYREF

addr_len = 128;
v7 = 0LL;
v8 = 0;
v9 = 0;
*(_OWORD *)buf = 0LL;
v6 = 0LL;
while ( 1 )
{
while ( 1 )
{
v1 = accept(fd, &addr, &addr_len);
if ( v1 != -1 )
break;
perror("\x1B[0;31maccept");
}
v2 = get_in_addr(&addr);
inet_ntop(addr.sa_family, v2, buf, v3);
printf("\x1B[0;32mserver: got connection from %s\n", buf);
if ( (unsigned int)incoming_socket_serv(fd, v1) == -1 )
puts("\x1B[0;31mserver: client process failed");
close(v1);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func6(int fd)
{
int v1; // ebp
_WORD *v2; // rax
socklen_t v3; // ecx
socklen_t addr_len; // [rsp+0h] [rbp-CCh] BYREF
char buf[16]; // [rsp+4h] [rbp-C8h] BYREF
__int128 v6; // [rsp+14h] [rbp-B8h]
__int64 v7; // [rsp+24h] [rbp-A8h]
int v8; // [rsp+2Ch] [rbp-A0h]
__int16 v9; // [rsp+30h] [rbp-9Ch]
struct sockaddr addr; // [rsp+34h] [rbp-98h] BYREF

addr_len = 128;
v7 = 0LL;
v8 = 0;
v9 = 0;
*(_OWORD *)buf = 0LL;
v6 = 0LL;
while ( 1 )
{
while ( 1 )
{
v1 = accept(fd, &addr, &addr_len);
if ( v1 != -1 )
break;
perror("\x1B[0;31maccept");
}
v2 = get_in_addr(&addr);
inet_ntop(addr.sa_family, v2, buf, v3);
printf("\x1B[0;32mserver: got connection from %s\n", buf);
if ( (unsigned int)func5(fd, v1) == -1 )
puts("\x1B[0;31mserver: client process failed");
close(v1);
}
}

original_code:
void incoming_socket_wait(int sfd) {
    struct sockaddr_storage client;
    socklen_t clen = sizeof(client);
    int afd = -1;
    char dst[46] = { '\0' };
    for (;;) {
        if ((afd = accept(sfd, (struct sockaddr *)&client, &clen)) == -1) {
            perror("\x1B[0;31m" "accept");
            continue;
        }
        inet_ntop( client.ss_family,
                   get_in_addr( (struct sockaddr *) &client ),
                   dst,
                   sizeof(dst));
        printf("\x1B[0;32m" "server: got connection from %s\n", dst);
        if (incoming_socket_serv(sfd, afd) == -1) {
            printf("\x1B[0;31m" "server: client process failed\n");
        }
        close(afd);
    }
}

canonical_original_code:
void incoming_socket_wait(int sfd) {
    struct sockaddr_storage client;
    unsigned int clen = sizeof(client);
    int afd = -1;
    char dst[46] = { '\0' };
    for (;;) {
        if ((afd = accept(sfd, (struct sockaddr *)&client, &clen)) == -1) {
            perror("\x1B[0;31m" "accept");
            continue;
        }
        inet_ntop( client.ss_family,
                   get_in_addr( (struct sockaddr *) &client ),
                   dst,
                   sizeof(dst));
        printf("\x1B[0;32m" "server: got connection from %s\n", dst);
        if (incoming_socket_serv(sfd, afd) == -1) {
            printf("\x1B[0;31m" "server: client process failed\n");
        }
        close(afd);
    }
}

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

variable_types:
clen
unsigned int

variable_types:
dst
char [46]

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


decompiled_code:
int print_greeting()
{
puts("\x1B[0mType characters at the prompt and they will be echoed back");
return puts("Type 'quit' to quit the session.");
}

canonical_decompiled_code:
int func1()
{
puts("\x1B[0mType characters at the prompt and they will be echoed back");
return puts("Type 'quit' to quit the session.");
}

original_code:
void print_greeting() {
    printf("\x1B[0m" "Type characters at the prompt and they will be echoed back\n");
    printf("Type 'quit' to quit the session.\n");
}


decompiled_code:
__int64 __fastcall connection_attempt(const char *a1, const char *a2)
{
unsigned int v2; // er12
int v3; // eax
struct addrinfo *i; // rbx
int v5; // eax
_WORD *v6; // rax
socklen_t v7; // ecx
const char *v9; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-80h] BYREF
char buf[16]; // [rsp+8h] [rbp-78h] BYREF
__int128 v12; // [rsp+18h] [rbp-68h]
__int64 v13; // [rsp+28h] [rbp-58h]
int v14; // [rsp+30h] [rbp-50h]
__int16 v15; // [rsp+34h] [rbp-4Ch]
struct addrinfo req; // [rsp+38h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
pai = 0LL;
v13 = 0LL;
v14 = 0;
v15 = 0;
req.ai_socktype = 1;
*(_OWORD *)buf = 0LL;
v12 = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v3 = getaddrinfo(a1, a2, &req, &pai);
if ( v3 )
{
v2 = -1;
v9 = gai_strerror(v3);
fprintf(stderr, "\x1B[0;31mgetaddrinfo: %s\n", v9);
return v2;
}
for ( i = pai; i; i = i->ai_next )
{
v5 = socket(i->ai_family, i->ai_socktype, i->ai_protocol);
v2 = v5;
if ( v5 == -1 )
{
perror("\x1B[0;33mclient: socket");
}
else
{
if ( connect(v5, i->ai_addr, i->ai_addrlen) != -1 )
{
v6 = get_in_addr(&i->ai_addr->sa_family);
inet_ntop(i->ai_family, v6, buf, v7);
printf("\x1B[0;33mclient: connecting to %s\n", buf);
freeaddrinfo(pai);
return v2;
}
close(v2);
perror("\x1B[0;33mclient: connection_attempt");
}
}
if ( v2 == -1 )
{
close(-1);
return v2;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
unsigned int v2; // er12
int v3; // eax
struct addrinfo *i; // rbx
int v5; // eax
_WORD *v6; // rax
socklen_t v7; // ecx
const char *v9; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-80h] BYREF
char buf[16]; // [rsp+8h] [rbp-78h] BYREF
__int128 v12; // [rsp+18h] [rbp-68h]
__int64 v13; // [rsp+28h] [rbp-58h]
int v14; // [rsp+30h] [rbp-50h]
__int16 v15; // [rsp+34h] [rbp-4Ch]
struct addrinfo req; // [rsp+38h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
pai = 0LL;
v13 = 0LL;
v14 = 0;
v15 = 0;
req.ai_socktype = 1;
*(_OWORD *)buf = 0LL;
v12 = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v3 = getaddrinfo(a1, a2, &req, &pai);
if ( v3 )
{
v2 = -1;
v9 = gai_strerror(v3);
fprintf(stderr, "\x1B[0;31mgetaddrinfo: %s\n", v9);
return v2;
}
for ( i = pai; i; i = i->ai_next )
{
v5 = socket(i->ai_family, i->ai_socktype, i->ai_protocol);
v2 = v5;
if ( v5 == -1 )
{
perror("\x1B[0;33mclient: socket");
}
else
{
if ( connect(v5, i->ai_addr, i->ai_addrlen) != -1 )
{
v6 = get_in_addr(&i->ai_addr->sa_family);
inet_ntop(i->ai_family, v6, buf, v7);
printf("\x1B[0;33mclient: connecting to %s\n", buf);
freeaddrinfo(pai);
return v2;
}
close(v2);
perror("\x1B[0;33mclient: connection_attempt");
}
}
if ( v2 == -1 )
{
close(-1);
return v2;
}
return 0xFFFFFFFFLL;
}

original_code:
int connection_attempt(const char *hostname, const char *port) {
    struct addrinfo hints;
    struct addrinfo *p = ((void *)0);
    struct addrinfo *pservinfo = ((void *)0);
    int fd;
    int result;
    char dst[46] = { '\0' };
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    if ((result = getaddrinfo(hostname, port, &hints, &pservinfo)) != 0) {
        fprintf(stderr, "\x1B[0;31m" "getaddrinfo: %s\n", gai_strerror(result));
        return -1;
     }
    for (p = pservinfo; p != ((void *)0); p = p->ai_next) {
        if ((fd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
            perror("\x1B[0;33m" "client: socket");
            continue;
        }
        if ((result = connect(fd, p->ai_addr, p->ai_addrlen)) == -1) {
            close(fd);
            perror("\x1B[0;33m" "client: connection_attempt");
            continue;
        }
        break;
    }
    if (p == ((void *)0)) {
        goto error;
    }
    inet_ntop(p->ai_family,
              get_in_addr((struct sockaddr *)p->ai_addr),
              dst,
              sizeof(dst));
    printf("\x1B[0;33m" "client: connecting to %s\n", dst);
    freeaddrinfo(pservinfo);
    return fd;
error:
     if (fd == -1) {
        close(fd);
     }
     return -1;
}

canonical_original_code:
int connection_attempt(char *hostname, char *port) {
    struct addrinfo hints;
    struct addrinfo *p = ((void *)0);
    struct addrinfo *pservinfo = ((void *)0);
    int fd;
    int result;
    char dst[46] = { '\0' };
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    if ((result = getaddrinfo(hostname, port, &hints, &pservinfo)) != 0) {
        fprintf(stderr, "\x1B[0;31m" "getaddrinfo: %s\n", gai_strerror(result));
        return -1;
     }
    for (p = pservinfo; p != ((void *)0); p = p->ai_next) {
        if ((fd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
            perror("\x1B[0;33m" "client: socket");
            continue;
        }
        if ((result = connect(fd, p->ai_addr, p->ai_addrlen)) == -1) {
            close(fd);
            perror("\x1B[0;33m" "client: connection_attempt");
            continue;
        }
        break;
    }
    if (p == ((void *)0)) {
        goto error;
    }
    inet_ntop(p->ai_family,
              get_in_addr((struct sockaddr *)p->ai_addr),
              dst,
              sizeof(dst));
    printf("\x1B[0;33m" "client: connecting to %s\n", dst);
    freeaddrinfo(pservinfo);
    return fd;
error:
     if (fd == -1) {
        close(fd);
     }
     return -1;
}

variable_types:
hostname
char *

variable_types: fd int


decompiled_code:
__ssize_t __fastcall process_input(char *a1, size_t a2)
{
__ssize_t result; // rax
size_t v3; // [rsp+0h] [rbp-18h] BYREF
char *lineptr; // [rsp+8h] [rbp-10h] BYREF

lineptr = a1;
v3 = a2;
printf("\n> ");
result = getline(&lineptr, &v3, stdin);
if ( !strcmp(lineptr, "quit\n") || !strcmp(lineptr, "QUIT\n") )
{
puts("Goodbye!");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__ssize_t __fastcall func3(char *a1, size_t a2)
{
__ssize_t result; // rax
size_t v3; // [rsp+0h] [rbp-18h] BYREF
char *lineptr; // [rsp+8h] [rbp-10h] BYREF

lineptr = a1;
v3 = a2;
printf("\n> ");
result = getline(&lineptr, &v3, stdin);
if ( !strcmp(lineptr, "quit\n") || !strcmp(lineptr, "QUIT\n") )
{
puts("Goodbye!");
result = 0LL;
}
return result;
}

original_code:
int process_input(char *buf, size_t bufsize) {
    int inbytes = 0;
    printf("\n> ");
    inbytes = getline(&buf, &bufsize, stdin);
    if (strcmp(buf, "quit\n") == 0
         || strcmp(buf, "QUIT\n") == 0) {
        printf("Goodbye!\n");
        return 0;
    }
    return inbytes;
}

canonical_original_code:
int process_input(char *buf, unsigned long bufsize) {
    int inbytes = 0;
    printf("\n> ");
    inbytes = getline(&buf, &bufsize, stdin);
    if (strcmp(buf, "quit\n") == 0
         || strcmp(buf, "QUIT\n") == 0) {
        printf("Goodbye!\n");
        return 0;
    }
    return inbytes;
}

variable_types:
buf
char *

variable_types:
bufsize
unsigned long

variable_types: inbytes int


main

repo: domroselli/tictactoe

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int128 v4[2]; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+20h] [rbp-18h]

v5 = 0;
v4[0] = 0LL;
v4[1] = 0LL;
init_board(v4, 9LL, envp);
print_instructions();
do
show_board(v4);
while ( (unsigned int)process_input(v4) );
show_board(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int128 v4[2]; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+20h] [rbp-18h]

v5 = 0;
v4[0] = 0LL;
v4[1] = 0LL;
func8(v4, 9LL, envp);
func7();
do
func10(v4);
while ( (unsigned int)func20(v4) );
func10(v4);
return 0;
}

original_code:
int main()
{
    int board[9] = {0};
    init_board(board, 9);
    print_instructions();
    do
    {
        show_board(board);
    }while(process_input(board));
    show_board(board);
    return 0;
}

variable_types:
board
int [9]


decompiled_code:
int print_instructions()
{
puts("TIC TAC TOE!");
puts("============\n");
puts("Choose the number of the square you want to put an 'x'");
puts("The computer will choose a square for an 'o'");
return puts("Continue placing x's until you get 3-in-a-row for the win!\n");
}

canonical_decompiled_code:
int func7()
{
puts("TIC TAC TOE!");
puts("============\n");
puts("Choose the number of the square you want to put an 'x'");
puts("The computer will choose a square for an 'o'");
return puts("Continue placing x's until you get 3-in-a-row for the win!\n");
}

original_code:
void print_instructions()
{
    printf("TIC TAC TOE!\n");
    printf("============\n\n");
    printf("Choose the number of the square you want to put an 'x'\n");
    printf("The computer will choose a square for an 'o'\n");
    printf("Continue placing x's until you get 3-in-a-row for the win!\n\n");
}


decompiled_code:
void __fastcall init_board(__int64 a1, int a2)
{
__int64 i; // rax

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
*(_DWORD *)(a1 + 4 * i) = i;
}
}

original_code:
void init_board(int b[], int n)
{
    int i = 0;
    for (i = 0; i < n; i++)
    {
        b[i] = i;
    }
}

variable_types:
b
int []

variable_types: n int

variable_types: i int


dtoc

decompiled_code:
__int64 __fastcall dtoc(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( a1 != 120 && a1 != 111 )
result = a1 + 48;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
__int64 result; // rax

result = a1;
if ( a1 != 120 && a1 != 111 )
result = a1 + 48;
return result;
}

original_code:
int dtoc(int d)
{
    if (d == 'x' || d == 'o')
    {
        return d;
    }
    else
    {
        return d + '0';
    }
}

variable_types: d int


decompiled_code:
int __fastcall show_board(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // er9
unsigned int v3; // er8
unsigned int v4; // eax
unsigned int v5; // er9
unsigned int v6; // er8
unsigned int v7; // eax
unsigned int v8; // er9
unsigned int v9; // er8

dtoc(a1[2]);
dtoc(a1[1]);
v1 = dtoc(*a1);
printf("%c | %c | %c\n", v1, v3, v2);
puts("----------");
dtoc(a1[5]);
dtoc(a1[4]);
v4 = dtoc(a1[3]);
printf("%c | %c | %c\n", v4, v6, v5);
puts("----------");
dtoc(a1[8]);
dtoc(a1[7]);
v7 = dtoc(a1[6]);
return printf("%c | %c | %c\n", v7, v9, v8);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // er9
unsigned int v3; // er8
unsigned int v4; // eax
unsigned int v5; // er9
unsigned int v6; // er8
unsigned int v7; // eax
unsigned int v8; // er9
unsigned int v9; // er8

func9(a1[2]);
func9(a1[1]);
v1 = func9(*a1);
printf("%c | %c | %c\n", v1, v3, v2);
puts("----------");
func9(a1[5]);
func9(a1[4]);
v4 = func9(a1[3]);
printf("%c | %c | %c\n", v4, v6, v5);
puts("----------");
func9(a1[8]);
func9(a1[7]);
v7 = func9(a1[6]);
return printf("%c | %c | %c\n", v7, v9, v8);
}


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

if ( fgets(s, a2, _bss_start) )
result = strlen(s);
else
result = 0LL;
return result;
}

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

if ( fgets(s, a2, _bss_start) )
result = strlen(s);
else
result = 0LL;
return result;
}

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

canonical_original_code:
unsigned long get_input(char *line, int max)
{
    if (fgets(line, max, stdin) == ((void *)0))
    {
        return 0;
    }
    else
    {
        return strlen(line);
    }
}

variable_types:
line
char *

variable_types: max int

return_type: unsigned long


decompiled_code:
__int64 __fastcall computer_tryagain(_DWORD *a1)
{
_DWORD *v1; // rax

v1 = a1 + 9;
while ( *a1 )
{
if ( ++a1 == v1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(_DWORD *a1)
{
_DWORD *v1; // rax

v1 = a1 + 9;
while ( *a1 )
{
if ( ++a1 == v1 )
return 0LL;
}
return 1LL;
}

original_code:
int computer_tryagain(int tries[])
{
    int i = 0;
    for (i = 0; i < 9; i++)
    {
        if (!tries[i])
        {
            return 1;
        }
    }
    return 0;
}

variable_types:
tries
int []


decompiled_code:
__int64 __fastcall computer_move(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax
_DWORD *v3; // rsi
__int128 v5[2]; // [rsp+0h] [rbp-48h] BYREF
int v6; // [rsp+20h] [rbp-28h]

v1 = time(0LL);
srand(v1);
v6 = 0;
v5[0] = 0LL;
v5[1] = 0LL;
while ( 1 )
{
do
LODWORD(result) = rand() % 9;
while ( *((_DWORD *)v5 + (int)result) );
v3 = (_DWORD *)(a1 + 4LL * (int)result);
if ( *v3 != 120 && *v3 != 111 )
break;
*((_DWORD *)v5 + (int)result) = 1;
if ( !(unsigned int)computer_tryagain(v5) )
return 0LL;
}
*v3 = 111;
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax
_DWORD *v3; // rsi
__int128 v5[2]; // [rsp+0h] [rbp-48h] BYREF
int v6; // [rsp+20h] [rbp-28h]

v1 = time(0LL);
srand(v1);
v6 = 0;
v5[0] = 0LL;
v5[1] = 0LL;
while ( 1 )
{
do
LODWORD(result) = rand() % 9;
while ( *((_DWORD *)v5 + (int)result) );
v3 = (_DWORD *)(a1 + 4LL * (int)result);
if ( *v3 != 120 && *v3 != 111 )
break;
*((_DWORD *)v5 + (int)result) = 1;
if ( !(unsigned int)func12(v5) )
return 0LL;
}
*v3 = 111;
return (unsigned int)result;
}

original_code:
int computer_move(int board[])
{
    srand(time(((void *)0)));
    int i = 0;
    int tries[9] = {0};
    int tryagain = 1;
    while (tryagain)
    {
        i = rand() % 9;
        if (tries[i]) continue;
        if (board[i] != 'x' && board[i] != 'o')
        {
            board[i] = 'o';
            return i;
        }
        tries[i] = 1;
        tryagain = computer_tryagain(tries);
    }
    return 0;
}

variable_types:
board
int []

variable_types:
tries
int [9]

variable_types: tryagain int


decompiled_code:
_BOOL8 __fastcall check_row(__int64 a1, char a2, int a3, int a4, int a5)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_DWORD *)(a1 + 4LL * a3) == a2 && a2 == *(_DWORD *)(a1 + 4LL * a4) )
result = *(_DWORD *)(a1 + 4LL * a5) == a2;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(__int64 a1, char a2, int a3, int a4, int a5)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_DWORD *)(a1 + 4LL * a3) == a2 && a2 == *(_DWORD *)(a1 + 4LL * a4) )
result = *(_DWORD *)(a1 + 4LL * a5) == a2;
return result;
}

original_code:
int check_row(int board[], char p, int c1, int c2, int c3)
{
    if (board[c1] == p && board[c2] == p && board[c3] == p)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types: p char


original_code:
int is_winner(int board[], char p)
{
    if (check_row(board, p, 0, 1, 2))
        return 1;
    if (check_row(board, p, 3, 4, 5))
        return 1;
    if (check_row(board, p, 6, 7, 8))
        return 1;
    if (check_row(board, p, 0, 3, 6))
        return 1;
    if (check_row(board, p, 1, 4, 7))
        return 1;
    if (check_row(board, p, 2, 5, 8))
        return 1;
    if (check_row(board, p, 0, 4, 8))
        return 1;
    if (check_row(board, p, 2, 4, 6))
        return 1;
    return 0;
}


decompiled_code:
__int64 __fastcall is_stalemate(_DWORD *a1)
{
_DWORD *v1; // rdx

v1 = a1 + 9;
while ( *a1 == 120 || *a1 == 111 )
{
if ( v1 == ++a1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(_DWORD *a1)
{
_DWORD *v1; // rdx

v1 = a1 + 9;
while ( *a1 == 120 || *a1 == 111 )
{
if ( v1 == ++a1 )
return 1LL;
}
return 0LL;
}

original_code:
int is_stalemate(int board[])
{
    int i = 0;
    for (i = 0; i < 9; i++)
    {
        if (board[i] != 'x' && board[i] != 'o')
        {
            return 0;
        }
    }
    return 1;
}


decompiled_code:
_BOOL8 __fastcall is_quitting(int a1)
{
return (a1 & 0xFFFFFFDF) == 81;
}

canonical_decompiled_code:
_BOOL8 __fastcall func17(int a1)
{
return (a1 & 0xFFFFFFDF) == 81;
}

original_code:
int is_quitting(int c)
{
    if (c == 'q' || c == 'Q')
    {
        return 1;
    }
    return 0;
}

variable_types: c int


decompiled_code:
__int64 __fastcall player_move(__int64 a1, int a2)
{
_DWORD *v2; // rdx

v2 = (_DWORD *)(a1 + 4LL * a2);
if ( *v2 == 120 || *v2 == 111 )
return 0LL;
*v2 = 120;
return 1LL;
}

original_code:
int player_move(int board[], int i)
{
    if (board[i] != 'x' && board[i] != 'o')
    {
        board[i] = 'x';
        return 1;
    }
    return 0;
}


decompiled_code:
_BOOL8 __fastcall is_input_invalid(char *a1)
{
return (unsigned int)(*a1 - 48) > 8;
}

canonical_decompiled_code:
_BOOL8 __fastcall func19(char *a1)
{
return (unsigned int)(*a1 - 48) > 8;
}

original_code:
int is_input_invalid(char input[], size_t len)
{
    if (len < 0 && len > 2)
    {
        return 1;
    }
    int i = input[0] - '0';
    if (i >= 0 && i < 9)
    {
        return 0;
    }
    return 1;
}

canonical_original_code:
int is_input_invalid(char input[], unsigned long len)
{
    if (len < 0 && len > 2)
    {
        return 1;
    }
    int i = input[0] - '0';
    if (i >= 0 && i < 9)
    {
        return 0;
    }
    return 1;
}

variable_types:
input
char []

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall process_input(_DWORD *a1)
{
_BOOL4 v1; // er12
__int64 result; // rax
int v3; // esi
__int128 v4[6]; // [rsp+0h] [rbp-68h] BYREF

printf("\n>");
v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v4[4] = 0LL;
get_input((char *)v4, 80);
if ( is_input_invalid((char *)v4) )
{
if ( is_quitting(SLOBYTE(v4[0])) )
{
LABEL_3:
v1 = 0;
puts("Giving up? Lame.");
return v1;
}
puts("Invalid square. Try again\n");
result = 1LL;
}
else
{
v3 = SLOBYTE(v4[0]);
v1 = is_quitting(SLOBYTE(v4[0]));
if ( v1 )
goto LABEL_3;
if ( (unsigned int)player_move((__int64)a1, v3 - 48) )
{
if ( !(unsigned int)is_winner((__int64)a1, 120) )
{
if ( (unsigned int)computer_move((__int64)a1) && (unsigned int)is_winner((__int64)a1, 111) )
{
puts("You lose :(");
}
else
{
v1 = 1;
if ( (unsigned int)is_stalemate(a1) )
{
v1 = 0;
puts("Stalemate");
}
}
return v1;
}
puts("You WIN!");
result = 0LL;
}
else
{
puts("That one is already in use. Try again.");
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(_DWORD *a1)
{
_BOOL4 v1; // er12
__int64 result; // rax
int v3; // esi
__int128 v4[6]; // [rsp+0h] [rbp-68h] BYREF

printf("\n>");
v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = 0LL;
v4[3] = 0LL;
v4[4] = 0LL;
func11((char *)v4, 80);
if ( func19((char *)v4) )
{
if ( func17(SLOBYTE(v4[0])) )
{
LABEL_3:
v1 = 0;
puts("Giving up? Lame.");
return v1;
}
puts("Invalid square. Try again\n");
result = 1LL;
}
else
{
v3 = SLOBYTE(v4[0]);
v1 = func17(SLOBYTE(v4[0]));
if ( v1 )
goto LABEL_3;
if ( (unsigned int)func18((__int64)a1, v3 - 48) )
{
if ( !(unsigned int)func15((__int64)a1, 120) )
{
if ( (unsigned int)func13((__int64)a1) && (unsigned int)func15((__int64)a1, 111) )
{
puts("You lose :(");
}
else
{
v1 = 1;
if ( (unsigned int)func16(a1) )
{
v1 = 0;
puts("Stalemate");
}
}
return v1;
}
puts("You WIN!");
result = 0LL;
}
else
{
puts("That one is already in use. Try again.");
result = 1LL;
}
}
return result;
}

original_code:
int process_input(int board[])
{
    printf("\n>");
    char input[80] = {0};
    size_t n = get_input(input, 80);
    if (is_input_invalid(input, n) && !is_quitting(input[0]))
    {
        printf("Invalid square. Try again\n\n");
        return 1;
    }
    if (is_quitting(input[0]))
    {
        printf("Giving up? Lame.\n");
        return 0;
    }
   int i = input[0] - '0';
   if (player_move(board, i))
   {
        if (is_winner(board, 'x'))
        {
            printf("You WIN!\n");
            return 0;
        }
        if (computer_move(board) && is_winner(board, 'o'))
        {
            printf("You lose :(\n");
            return 0;
        }
        else
        {
            if (is_stalemate(board))
            {
                printf("Stalemate\n");
                return 0;
            }
        }
    }
    else
    {
        printf("That one is already in use. Try again.\n");
    }
    return 1;
}

canonical_original_code:
int process_input(int board[])
{
    printf("\n>");
    char input[80] = {0};
    unsigned long n = get_input(input, 80);
    if (is_input_invalid(input, n) && !is_quitting(input[0]))
    {
        printf("Invalid square. Try again\n\n");
        return 1;
    }
    if (is_quitting(input[0]))
    {
        printf("Giving up? Lame.\n");
        return 0;
    }
   int i = input[0] - '0';
   if (player_move(board, i))
   {
        if (is_winner(board, 'x'))
        {
            printf("You WIN!\n");
            return 0;
        }
        if (computer_move(board) && is_winner(board, 'o'))
        {
            printf("You lose :(\n");
            return 0;
        }
        else
        {
            if (is_stalemate(board))
            {
                printf("Stalemate\n");
                return 0;
            }
        }
    }
    else
    {
        printf("That one is already in use. Try again.\n");
    }
    return 1;
}

variable_types:
input
char [80]

variable_types:
n
unsigned long


main

repo: donapieppo/libnss-ato

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
struct passwd *v4; // rbx
struct spwd *v5; // rax
struct spwd *v6; // rbx

v3 = "pippo.pluto";
if ( argc == 2 )
v3 = argv[1];
v4 = getpwnam(v3);
if ( !v4 )
return -1;
puts("FROM PASSWORD:");
printf("\tname: %s\n", v4->pw_name);
printf("\tdir: %s\n", v4->pw_dir);
printf("\tgecos: %s\n", v4->pw_gecos);
puts("FROM SHADOW:");
v5 = getspnam(v3);
v6 = v5;
if ( !v5 )
return -1;
printf("\tname: %s\n", v5->sp_namp);
printf("\tpass: %s\n", v6->sp_pwdp);
return 0;
}

original_code:
int main (int argc, char *argv[]){
 struct passwd *p;
 struct spwd *s;
 char *usern="pippo.pluto";
 if(argc ==2)
 {
  usern=argv[1];
 }
 if (!(p=getpwnam(usern))) {
  return -1;
 }
 printf("FROM PASSWORD:\n");
 printf("\tname:  %s\n", p->pw_name);
 printf("\tdir:   %s\n", p->pw_dir);
 printf("\tgecos: %s\n", p->pw_gecos);
 printf("FROM SHADOW:\n");
 if (!(s = getspnam(usern))) {
  return -1;
 }
 printf ("\tname:  %s\n", s->sp_namp);
 printf ("\tpass:  %s\n", s->sp_pwdp);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 struct passwd *p;
 struct spwd *s;
 char *usern = "pippo.pluto";
 if(argc ==2)
 {
  usern=argv[1];
 }
 if (!(p=getpwnam(usern))) {
  return -1;
 }
 printf("FROM PASSWORD:\n");
 printf("\tname:  %s\n", p->pw_name);
 printf("\tdir:   %s\n", p->pw_dir);
 printf("\tgecos: %s\n", p->pw_gecos);
 printf("FROM SHADOW:\n");
 if (!(s = getspnam(usern))) {
  return -1;
 }
 printf ("\tname:  %s\n", s->sp_namp);
 printf ("\tpass:  %s\n", s->sp_pwdp);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types: struct spwd { char *sp_namp; char *sp_pwdp; long sp_lstchg; long sp_min; long sp_max; long sp_warn; long sp_inact; long sp_expire; unsigned long sp_flag; } *

variable_types:
usern
char *


decompiled_code:
__int64 __fastcall get_static(__int64 *a1, __int64 *a2, int a3)
{
__int64 v3; // rax
__int64 v4; // r8

v3 = *a2;
if ( *a2 < (unsigned __int64)a3 )
return 0LL;
v4 = *a1;
*a1 += a3;
*a2 = v3 - a3;
return v4;
}

original_code:
static char *
get_static(char **buffer, size_t *buflen, int len)
{
 char *result;
 if ((buffer == ((void *)0)) || (buflen == ((void *)0)) || (*buflen < len)) {
  return ((void *)0);
 }
 result = *buffer;
 *buffer += len;
 *buflen -= len;
 return result;
}

canonical_original_code:
static char *get_static(char **buffer, unsigned long *buflen, int len)
{
 char *result;
 if ((buffer == ((void *)0)) || (buflen == ((void *)0)) || (*buflen < len)) {
  return ((void *)0);
 }
 result = *buffer;
 *buffer += len;
 *buflen -= len;
 return result;
}

variable_types:
buffer
char **

variable_types:
buflen
unsigned long *

variable_types: len int

variable_types:
result
char *


repo: donbright/opengl-framebuffer-mini

decompiled_code:
__int64 draw_scene()
{
_BYTE v1[262144]; // [rsp-40000h] [rbp-40030h] BYREF
char s[40]; // [rsp+0h] [rbp-30h] BYREF

_glewBindFramebufferEXT(36160LL, (unsigned int)fboId);
glClearColor(1.0, 1.0, 1.0);
glClear(0x4000LL);
glPushMatrix();
glRotatef((float)angle, 0.0, 0.0, 1.0);
glBegin(4LL);
glColor3f(1.0, 0.0);
glVertex3f(0.0, 0.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC1), 0.0);
glVertex3f(0.0, COERCE_DOUBLE((unsigned __int64)LC1));
glEnd();
glPopMatrix();
angle += 15;
glReadPixels(0LL, 0LL, 256LL, 256LL, 32993LL, 5121LL, v1);
snprintf(s, 0x1EuLL, "test%04i.tga", (unsigned int)angle);
printf("writing %s\n", s);
write_targa(s, (__int64)v1, 256, 256);
return _glewBindFramebufferEXT(36160LL, 0LL);
}

canonical_decompiled_code:
__int64 func1()
{
_BYTE v1[262144]; // [rsp-40000h] [rbp-40030h] BYREF
char s[40]; // [rsp+0h] [rbp-30h] BYREF

_glewBindFramebufferEXT(36160LL, (unsigned int)fboId);
glClearColor(1.0, 1.0, 1.0);
glClear(0x4000LL);
glPushMatrix();
glRotatef((float)angle, 0.0, 0.0, 1.0);
glBegin(4LL);
glColor3f(1.0, 0.0);
glVertex3f(0.0, 0.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC1), 0.0);
glVertex3f(0.0, COERCE_DOUBLE((unsigned __int64)LC1));
glEnd();
glPopMatrix();
angle += 15;
glReadPixels(0LL, 0LL, 256LL, 256LL, 32993LL, 5121LL, v1);
snprintf(s, 0x1EuLL, "test%04i.tga", (unsigned int)angle);
printf("writing %s\n", s);
func0(s, (__int64)v1, 256, 256);
return _glewBindFramebufferEXT(36160LL, 0LL);
}

original_code:
void draw_scene()
{
 __glewBindFramebufferEXT(0x8D40, fboId);
 glClearColor(1, 1, 1, 1);
 glClear(0x00004000);
 glPushMatrix();
 glRotatef(angle, 0,0,1);
 glBegin(0x0004);
 glColor3f( 1, 0, 0);
 glVertex3f( 0, 0, 0);
 glVertex3f( 1, 0, 0);
 glVertex3f( 0, 1, 0);
 glEnd();
 glPopMatrix();
 angle += 15;
 GLubyte pixels[IMAGE_WIDTH*IMAGE_HEIGHT*4];
 glReadPixels(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, 0x80E1, 0x1401, pixels);
 char fname[30];
 snprintf(fname,30,"test%04i.tga",angle);
 printf("writing %s\n",fname);
 write_targa(fname,pixels,IMAGE_WIDTH,IMAGE_HEIGHT);
 __glewBindFramebufferEXT(0x8D40, 0);
}

canonical_original_code:
void draw_scene()
{
 __glewBindFramebufferEXT(0x8D40, fboId);
 glClearColor(1, 1, 1, 1);
 glClear(0x00004000);
 glPushMatrix();
 glRotatef(angle, 0,0,1);
 glBegin(0x0004);
 glColor3f( 1, 0, 0);
 glVertex3f( 0, 0, 0);
 glVertex3f( 1, 0, 0);
 glVertex3f( 0, 1, 0);
 glEnd();
 glPopMatrix();
 angle += 15;
 unsigned char pixels[-1];
 glReadPixels(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, 0x80E1, 0x1401, pixels);
 char fname[30];
 snprintf(fname,30,"test%04i.tga",angle);
 printf("writing %s\n",fname);
 write_targa(fname,pixels,IMAGE_WIDTH,IMAGE_HEIGHT);
 __glewBindFramebufferEXT(0x8D40, 0);
}

variable_types:
pixels
unsigned char [-1]

variable_types:
fname
char [30]


decompiled_code:
__int64 init_dummy_window()
{
return glx_dummy();
}

canonical_decompiled_code:
__int64 func2()
{
return glx_dummy();
}

original_code:
void init_dummy_window(int argc, char **argv)
{
 glx_dummy();
}

variable_types:
argv
char **


decompiled_code:
__int64 check_fbo_status()
{
unsigned int v0; // ebp
__int64 result; // rax
unsigned int v2; // eax

v0 = _glewCheckFramebufferStatusEXT(36160LL);
if ( (unsigned int)glGetError() )
{
v2 = glGetError();
printf("OpenGL Error %i\n", v2);
}
if ( v0 == 36053 )
{
puts("OpenGL Framebuffer object status is OK");
result = 0LL;
}
else
{
printf("OpenGL error setting up Framebuffer Object: ");
if ( v0 == 36061 )
{
puts("GL_FRAMEBUFFER_UNSUPPORTED_EXT");
result = 0xFFFFFFFFLL;
}
else if ( v0 == 36054 )
{
puts("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT");
result = 0xFFFFFFFFLL;
}
else if ( v0 == 36055 )
{
puts("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT");
result = 0xFFFFFFFFLL;
}
else if ( v0 == 36057 )
{
puts("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT - width / height problems?");
result = 0xFFFFFFFFLL;
}
else if ( v0 == 36058 )
{
puts("GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT");
result = 0xFFFFFFFFLL;
}
else if ( v0 == 36059 )
{
puts("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT");
result = 0xFFFFFFFFLL;
}
else if ( v0 == 36060 )
{
puts("GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT");
result = 0xFFFFFFFFLL;
}
else
{
if ( v0 == 36182 )
puts("GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT");
else
printf("\n Unknown Code: glCheckFramebufferStatusEXT returned %i\n", v0);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebp
__int64 result; // rax
unsigned int v2; // eax

v0 = _glewCheckFramebufferStatusEXT(36160LL);
if ( (unsigned int)glGetError() )
{
v2 = glGetError();
printf("OpenGL Error %i\n", v2);
}
if ( v0 == 36053 )
{
puts("OpenGL Framebuffer object status is OK");
result = 0LL;
}
else
{
printf("OpenGL error setting up Framebuffer Object: ");
if ( v0 == 36061 )
{
puts("GL_FRAMEBUFFER_UNSUPPORTED_EXT");
result = 0xFFFFFFFFLL;
}
else if ( v0 == 36054 )
{
puts("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT");
result = 0xFFFFFFFFLL;
}
else if ( v0 == 36055 )
{
puts("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT");
result = 0xFFFFFFFFLL;
}
else if ( v0 == 36057 )
{
puts("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT - width / height problems?");
result = 0xFFFFFFFFLL;
}
else if ( v0 == 36058 )
{
puts("GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT");
result = 0xFFFFFFFFLL;
}
else if ( v0 == 36059 )
{
puts("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT");
result = 0xFFFFFFFFLL;
}
else if ( v0 == 36060 )
{
puts("GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT");
result = 0xFFFFFFFFLL;
}
else
{
if ( v0 == 36182 )
puts("GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT");
else
printf("\n Unknown Code: glCheckFramebufferStatusEXT returned %i\n", v0);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int check_fbo_status()
{
 GLenum status;
 int result = -1;
 status = __glewCheckFramebufferStatusEXT(0x8D40);
 if (glGetError() != 0)
  printf("OpenGL Error %i\n",glGetError());
 if (status == 0x8CD5) {
  printf("OpenGL Framebuffer object status is OK\n");
  result = 0;
 } else {
  printf("OpenGL error setting up Framebuffer Object: ");
 }
 if (status == 0x8CDD)
  printf("GL_FRAMEBUFFER_UNSUPPORTED_EXT\n");
 else if (status == 0x8CD6)
  printf("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT\n");
 else if (status == 0x8CD7)
  printf("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT\n");
 else if (status == 0x8CD9)
  printf("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT - width / height problems?\n");
 else if (status == 0x8CDA)
  printf("GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT\n");
 else if (status == 0x8CDB)
  printf("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT\n");
 else if (status == 0x8CDC)
  printf("GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT\n");
 else if (status == 0x8D56)
  printf("GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT\n");
 else if (result !=0 ) {
  printf("\n Unknown Code: glCheckFramebufferStatusEXT returned %i\n",status);
 }
 return result;
}

canonical_original_code:
int check_fbo_status()
{
 unsigned int status;
 int result = -1;
 status = __glewCheckFramebufferStatusEXT(0x8D40);
 if (glGetError() != 0)
  printf("OpenGL Error %i\n",glGetError());
 if (status == 0x8CD5) {
  printf("OpenGL Framebuffer object status is OK\n");
  result = 0;
 } else {
  printf("OpenGL error setting up Framebuffer Object: ");
 }
 if (status == 0x8CDD)
  printf("GL_FRAMEBUFFER_UNSUPPORTED_EXT\n");
 else if (status == 0x8CD6)
  printf("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT\n");
 else if (status == 0x8CD7)
  printf("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT\n");
 else if (status == 0x8CD9)
  printf("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT - width / height problems?\n");
 else if (status == 0x8CDA)
  printf("GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT\n");
 else if (status == 0x8CDB)
  printf("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT\n");
 else if (status == 0x8CDC)
  printf("GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT\n");
 else if (status == 0x8D56)
  printf("GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT\n");
 else if (result !=0 ) {
  printf("\n Unknown Code: glCheckFramebufferStatusEXT returned %i\n",status);
 }
 return result;
}

variable_types:
status
unsigned int

variable_types: result int


decompiled_code:
int check_glerror()
{
unsigned int v0; // eax
int result; // eax
unsigned int v2; // eax

v0 = glGetError();
printf("OpenGL Error status: %i\n", v0);
result = glGetError();
if ( result )
{
v2 = glGetError();
result = printf("OpenGL Error status: %i\n", v2);
}
return result;
}

canonical_decompiled_code:
int func4()
{
unsigned int v0; // eax
int result; // eax
unsigned int v2; // eax

v0 = glGetError();
printf("OpenGL Error status: %i\n", v0);
result = glGetError();
if ( result )
{
v2 = glGetError();
result = printf("OpenGL Error status: %i\n", v2);
}
return result;
}

original_code:
void check_glerror()
{
 printf( "OpenGL Error status: %i\n", glGetError());
 if (glGetError())
  printf( "OpenGL Error status: %i\n", glGetError());
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // al
unsigned __int8 v4; // al

init_dummy_window(argc, argv, envp);
glewInit();
v3 = glewIsSupported("GL_ARB_framebuffer_object");
printf("ARB FBO: %i\n", v3);
v4 = glewIsSupported("GL_EXT_framebuffer_object");
printf("EXT FBO: %i\n", v4);
printf("%i\n", 36160LL);
_glewGenFramebuffersEXT(1LL, &fboId);
check_glerror();
_glewBindFramebufferEXT(36160LL, (unsigned int)fboId);
check_glerror();
_glewGenRenderbuffersEXT(1LL, &renderbufferId);
check_glerror();
_glewBindRenderbufferEXT(36161LL, (unsigned int)renderbufferId);
check_glerror();
_glewRenderbufferStorageEXT(36161LL, 6408LL, 256LL, 256LL);
check_glerror();
_glewFramebufferRenderbufferEXT(36160LL, 36064LL, 36161LL, (unsigned int)renderbufferId);
check_glerror();
_glewCheckFramebufferStatusEXT(36160LL);
check_glerror();
if ( (int)check_fbo_status() < 0 )
return -1;
glViewport(0LL, 0LL, 256LL, 256LL);
draw_scene();
draw_scene();
draw_scene();
draw_scene();
_glewDeleteRenderbuffersEXT(1LL, &renderbufferId);
_glewDeleteFramebuffersEXT(1LL, &fboId);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // al
unsigned __int8 v4; // al

func2(argc, argv, envp);
glewInit();
v3 = glewIsSupported("GL_ARB_framebuffer_object");
printf("ARB FBO: %i\n", v3);
v4 = glewIsSupported("GL_EXT_framebuffer_object");
printf("EXT FBO: %i\n", v4);
printf("%i\n", 36160LL);
_glewGenFramebuffersEXT(1LL, &fboId);
func4();
_glewBindFramebufferEXT(36160LL, (unsigned int)fboId);
func4();
_glewGenRenderbuffersEXT(1LL, &renderbufferId);
func4();
_glewBindRenderbufferEXT(36161LL, (unsigned int)renderbufferId);
func4();
_glewRenderbufferStorageEXT(36161LL, 6408LL, 256LL, 256LL);
func4();
_glewFramebufferRenderbufferEXT(36160LL, 36064LL, 36161LL, (unsigned int)renderbufferId);
func4();
_glewCheckFramebufferStatusEXT(36160LL);
func4();
if ( (int)func3() < 0 )
return -1;
glViewport(0LL, 0LL, 256LL, 256LL);
func1();
func1();
func1();
func1();
_glewDeleteRenderbuffersEXT(1LL, &renderbufferId);
_glewDeleteFramebuffersEXT(1LL, &fboId);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 init_dummy_window(argc, argv);
 glewInit();
 printf("ARB FBO: %i\n",glewIsSupported("GL_ARB_framebuffer_object"));
 printf("EXT FBO: %i\n",glewIsSupported("GL_EXT_framebuffer_object"));
 printf("%i\n",0x8D40);
 __glewGenFramebuffersEXT(1, &fboId);
 check_glerror();
 __glewBindFramebufferEXT(0x8D40, fboId);
 check_glerror();
 __glewGenRenderbuffersEXT(1, &renderbufferId);
 check_glerror();
 __glewBindRenderbufferEXT(0x8D41, renderbufferId);
 check_glerror();
 __glewRenderbufferStorageEXT( 0x8D41, 0x1908, IMAGE_WIDTH, IMAGE_HEIGHT );
 check_glerror();
 __glewFramebufferRenderbufferEXT( 0x8D40, 0x8CE0, 0x8D41, renderbufferId );
 check_glerror();
 GLenum status = __glewCheckFramebufferStatusEXT(0x8D40);
 check_glerror();
 if (check_fbo_status() <0 ) return -1;
 glViewport(0,0,IMAGE_WIDTH,IMAGE_HEIGHT);
 int i;
 for (i=0;i<4;i++) draw_scene();
 __glewDeleteRenderbuffersEXT(1, &renderbufferId);
 __glewDeleteFramebuffersEXT(1, &fboId);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 init_dummy_window(argc, argv);
 glewInit();
 printf("ARB FBO: %i\n",glewIsSupported("GL_ARB_framebuffer_object"));
 printf("EXT FBO: %i\n",glewIsSupported("GL_EXT_framebuffer_object"));
 printf("%i\n",0x8D40);
 __glewGenFramebuffersEXT(1, &fboId);
 check_glerror();
 __glewBindFramebufferEXT(0x8D40, fboId);
 check_glerror();
 __glewGenRenderbuffersEXT(1, &renderbufferId);
 check_glerror();
 __glewBindRenderbufferEXT(0x8D41, renderbufferId);
 check_glerror();
 __glewRenderbufferStorageEXT( 0x8D41, 0x1908, IMAGE_WIDTH, IMAGE_HEIGHT );
 check_glerror();
 __glewFramebufferRenderbufferEXT( 0x8D40, 0x8CE0, 0x8D41, renderbufferId );
 check_glerror();
 unsigned int status = __glewCheckFramebufferStatusEXT(0x8D40);
 check_glerror();
 if (check_fbo_status() <0 ) return -1;
 glViewport(0,0,IMAGE_WIDTH,IMAGE_HEIGHT);
 int i;
 for (i=0;i<4;i++) draw_scene();
 __glewDeleteRenderbuffersEXT(1, &renderbufferId);
 __glewDeleteFramebuffersEXT(1, &fboId);
 return 0;
}

variable_types: i int


repo: dongrote/non-canonical-terminal

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

tcgetattr(0, &orig_stdin_termios);
atexit(restore_stdin_termios);
set_non_canonical_mode(0);
while ( read(0, buf, 1uLL) > 0 )
fprintf(_bss_start, "rx: 0x%02x\n", (unsigned __int8)buf[0]);
fwrite("Timeout reached. Exiting.\n", 1uLL, 0x1AuLL, _bss_start);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

tcgetattr(0, &orig_stdin_termios);
func11(restore_stdin_termios);
func8(0);
while ( read(0, buf, 1uLL) > 0 )
fprintf(_bss_start, "rx: 0x%02x\n", (unsigned __int8)buf[0]);
fwrite("Timeout reached. Exiting.\n", 1uLL, 0x1AuLL, _bss_start);
exit(0);
}

original_code:
int main() {
    uint8_t byte;
    tcgetattr(0, &orig_stdin_termios);
    atexit(restore_stdin_termios);
    set_non_canonical_mode(0);
    while( read(0, &byte, sizeof(byte)) > 0 ) {
        fprintf(stdout, "rx: 0x%02x\n", byte);
    }
    fprintf(stdout, "Timeout reached. Exiting.\n");
    exit(0);
}

canonical_original_code:
int main() {
    unsigned char byte;
    tcgetattr(0, &orig_stdin_termios);
    atexit(restore_stdin_termios);
    set_non_canonical_mode(0);
    while( read(0, &byte, sizeof(byte)) > 0 ) {
        fprintf(stdout, "rx: 0x%02x\n", byte);
    }
    fprintf(stdout, "Timeout reached. Exiting.\n");
    exit(0);
}

variable_types:
byte
unsigned char


decompiled_code:
int restore_stdin_termios()
{
fwrite("Restoring stdin termios settings.\n", 1uLL, 0x22uLL, _bss_start);
return tcsetattr(0, 0, &orig_stdin_termios);
}

canonical_decompiled_code:
int func7()
{
fwrite("Restoring stdin termios settings.\n", 1uLL, 0x22uLL, _bss_start);
return tcsetattr(0, 0, &orig_stdin_termios);
}

original_code:
void restore_stdin_termios(void) {
    fprintf(stdout, "Restoring stdin termios settings.\n");
    tcsetattr(0, 0, &orig_stdin_termios);
}

canonical_original_code:
void restore_stdin_termios() {
    fprintf(stdout, "Restoring stdin termios settings.\n");
    tcsetattr(0, 0, &orig_stdin_termios);
}


decompiled_code:
int __fastcall set_non_canonical_mode(int fd)
{
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(fd, &v2);
v2.c_lflag &= 0xFFFFFFF5;
*(_WORD *)&v2.c_cc[5] = 100;
return tcsetattr(fd, 0, &v2);
}

canonical_decompiled_code:
int __fastcall func8(int fd)
{
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(fd, &v2);
v2.c_lflag &= 0xFFFFFFF5;
*(_WORD *)&v2.c_cc[5] = 100;
return tcsetattr(fd, 0, &v2);
}

original_code:
void set_non_canonical_mode(int fd) {
    struct termios termios;
    tcgetattr(fd, &termios);
    termios.c_lflag &= ~(0000002);
    termios.c_lflag &= ~(0000010);
    termios.c_cc[5] = 100;
    termios.c_cc[6] = 0;
    tcsetattr(fd, 0, &termios);
}

variable_types: fd int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
int v5; // [rsp+8h] [rbp-10h] BYREF
char v6[12]; // [rsp+Ch] [rbp-Ch] BYREF

init_keystrokes(argc, argv, envp);
reg_keystroke(Mod_Shift | Mod_Super);
reg_keystroke(Mod_Alt | Mod_Control);
puts("Looking for (Super + Shift + a) or (Control + Alt + b)...");
while ( 1 )
{
while ( !(unsigned __int16)get_keystroke(v6, &v5) )
;
if ( v5 == 98 )
break;
puts("Got Keystroke!");
}
puts("You killed me!");
v3 = XKeysymToString(v5);
puts(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
int v5; // [rsp+8h] [rbp-10h] BYREF
char v6[12]; // [rsp+Ch] [rbp-Ch] BYREF

func11(argc, argv, envp);
func12(Mod_Shift | Mod_Super);
func12(Mod_Alt | Mod_Control);
puts("Looking for (Super + Shift + a) or (Control + Alt + b)...");
while ( 1 )
{
while ( !(unsigned __int16)func13(v6, &v5) )
;
if ( v5 == 98 )
break;
puts("Got Keystroke!");
}
puts("You killed me!");
v3 = XKeysymToString(v5);
puts(v3);
return 0;
}

original_code:
int main() {
 init_keystrokes();
 reg_keystroke(Mod_Super | Mod_Shift, 0x0061);
 reg_keystroke(Mod_Control | Mod_Alt, 0x0062);
 int keysym, state;
 printf("Looking for (Super + Shift + a) or (Control + Alt + b)...\n");
 while(1){
  if (get_keystroke(&state, &keysym)) {
   if (keysym == 0x0062) {
    printf("You killed me!\n");
    break;
   } else {
    printf("Got Keystroke!\n");
   }
  }
 }
 char *str = XKeysymToString(keysym);
 printf("%s\n", str);
 kill_keystrokes();
 return 0;
}

canonical_original_code:
int main() {
 init_keystrokes();
 reg_keystroke(Mod_Super | Mod_Shift, 0x0061);
 reg_keystroke(Mod_Control | Mod_Alt, 0x0062);
 int keysym; int state;
 printf("Looking for (Super + Shift + a) or (Control + Alt + b)...\n");
 while(1){
  if (get_keystroke(&state, &keysym)) {
   if (keysym == 0x0062) {
    printf("You killed me!\n");
    break;
   } else {
    printf("Got Keystroke!\n");
   }
  }
 }
 char *str = XKeysymToString(keysym);
 printf("%s\n", str);
 kill_keystrokes();
 return 0;
}

variable_types: keysym int

variable_types: state int

variable_types:
str
char *


keysymToChar

decompiled_code:
__int64 __fastcall keysymToChar(int a1)
{
return (unsigned __int8)*XKeysymToString(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return (unsigned __int8)*XKeysymToString(a1);
}

original_code:
char keysymToChar(int keysym) {
 return XKeysymToString(keysym)[0];
}

return_type: char


decompiled_code:
__int64 __fastcall is_modifier(int a1)
{
unsigned int v1; // er15
unsigned int v2; // ebx
XModifierKeymap *v3; // r14
__int64 v4; // r13
int v6; // [rsp+0h] [rbp-48h]
int v7; // [rsp+4h] [rbp-44h]
unsigned int v8; // [rsp+Ch] [rbp-3Ch]

v1 = 0;
v2 = 0;
v7 = 0;
v3 = XGetModifierMapping(disp);
v6 = v3->max_keypermod;
v8 = v3->max_keypermod - 1;
do
{
v4 = v7;
if ( v6 > 0 )
{
do
{
if ( XKeycodeToKeysym(disp, v3->modifiermap[v4], 0) == a1 )
v1 = v2;
++v4;
}
while ( v7 + (unsigned __int64)v8 + 1 != v4 );
}
++v2;
v7 += v6;
}
while ( v2 != 8 );
XFreeModifiermap(v3);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
unsigned int v1; // er15
unsigned int v2; // ebx
XModifierKeymap *v3; // r14
__int64 v4; // r13
int v6; // [rsp+0h] [rbp-48h]
int v7; // [rsp+4h] [rbp-44h]
unsigned int v8; // [rsp+Ch] [rbp-3Ch]

v1 = 0;
v2 = 0;
v7 = 0;
v3 = XGetModifierMapping(disp);
v6 = v3->max_keypermod;
v8 = v3->max_keypermod - 1;
do
{
v4 = v7;
if ( v6 > 0 )
{
do
{
if ( XKeycodeToKeysym(disp, v3->modifiermap[v4], 0) == a1 )
v1 = v2;
++v4;
}
while ( v7 + (unsigned __int64)v8 + 1 != v4 );
}
++v2;
v7 += v6;
}
while ( v2 != 8 );
XFreeModifiermap(v3);
return v1;
}

original_code:
short is_modifier(unsigned int keysym) {
 XModifierKeymap *map = XGetModifierMapping(disp);
 int max = map->max_keypermod;
 short pos = 0;
 int i, j;
 for (i = 0; i < 8; i++) {
  for (j = 0; j < max; j++) {
   if (XKeycodeToKeysym(disp, map->modifiermap[(i*max) + j], 0) == keysym) {
    pos = i;
   }
  }
 }
 XFreeModifiermap(map);
 return pos;
}

canonical_original_code:
short is_modifier(unsigned int keysym) {
 struct XModifierKeymap *map = XGetModifierMapping(disp);
 int max = map->max_keypermod;
 short pos = 0;
 int i; int j;
 for (i = 0; i < 8; i++) {
  for (j = 0; j < max; j++) {
   if (XKeycodeToKeysym(disp, map->modifiermap[(i*max) + j], 0) == keysym) {
    pos = i;
   }
  }
 }
 XFreeModifiermap(map);
 return pos;
}

variable_types:
keysym
unsigned int

variable_types: struct XModifierKeymap { int max_keypermod; unsigned char *modifiermap; } *

variable_types: max int

variable_types: pos short

variable_types: j int

return_type: short


decompiled_code:
__int64 init_keystrokes()
{
Window v0; // rax
__int64 result; // rax

disp = XOpenDisplay(0LL);
v0 = XDefaultRootWindow(disp);
XSelectInput(disp, v0, 1LL);
Mod_Control = 4;
Mod_Shift = 1;
if ( !(unsigned __int16)set_up_mod(&Mod_Alt, 65513) )
set_up_mod(&Mod_Alt, 65514);
result = set_up_mod(&Mod_Super, 65515);
if ( !(_WORD)result )
result = set_up_mod(&Mod_Super, 65516);
return result;
}

canonical_decompiled_code:
__int64 func11()
{
Window v0; // rax
__int64 result; // rax

disp = XOpenDisplay(0LL);
v0 = XDefaultRootWindow(disp);
XSelectInput(disp, v0, 1LL);
Mod_Control = 4;
Mod_Shift = 1;
if ( !(unsigned __int16)func10(&Mod_Alt, 65513) )
func10(&Mod_Alt, 65514);
result = func10(&Mod_Super, 65515);
if ( !(_WORD)result )
result = func10(&Mod_Super, 65516);
return result;
}

original_code:
void init_keystrokes() {
 disp = XOpenDisplay(0);
 Window root = XDefaultRootWindow(disp);
 XSelectInput(disp, root, (1L<<0));
 Mod_Control = (1<<2);
 Mod_Shift = (1<<0);
 if(!_set_up_mod(&Mod_Alt, 0xffe9)){_set_up_mod(&Mod_Alt, 0xffea);};
 if(!_set_up_mod(&Mod_Super, 0xffeb)){_set_up_mod(&Mod_Super, 0xffec);};
}

canonical_original_code:
void init_keystrokes() {
 disp = XOpenDisplay(0);
 unsigned long root = XDefaultRootWindow(disp);
 XSelectInput(disp, root, (1L<<0));
 Mod_Control = (1<<2);
 Mod_Shift = (1<<0);
 if(!_set_up_mod(&Mod_Alt, 0xffe9)){_set_up_mod(&Mod_Alt, 0xffea);};
 if(!_set_up_mod(&Mod_Super, 0xffeb)){_set_up_mod(&Mod_Super, 0xffec);};
}

variable_types:
root
unsigned long


decompiled_code:
__int64 __fastcall reg_keystroke(unsigned int a1, int a2)
{
Window v2; // r12
__int16 v3; // r8
__int64 result; // rax
KeyCode v5; // al

v2 = XDefaultRootWindow(disp);
XSelectInput(disp, v2, 1LL);
v3 = is_modifier(a2);
result = 0LL;
if ( !v3 )
{
v5 = XKeysymToKeycode(disp, a2);
XGrabKey(disp, v5, a1, v2, 0, 1, 1);
printf("Grabbing mods: %i\n", a1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, int a2)
{
Window v2; // r12
__int16 v3; // r8
__int64 result; // rax
KeyCode v5; // al

v2 = XDefaultRootWindow(disp);
XSelectInput(disp, v2, 1LL);
v3 = func9(a2);
result = 0LL;
if ( !v3 )
{
v5 = XKeysymToKeycode(disp, a2);
XGrabKey(disp, v5, a1, v2, 0, 1, 1);
printf("Grabbing mods: %i\n", a1);
result = 1LL;
}
return result;
}

original_code:
short reg_keystroke(int mods, int keysym) {
 Window root = XDefaultRootWindow(disp);
 XSelectInput(disp, root, (1L<<0));
 if (is_modifier(keysym))
  return 0;
 int code = XKeysymToKeycode(disp, keysym);
 XGrabKey(disp, code, mods, root, 0, 1, 1);
 printf("Grabbing mods: %i\n", mods);
 return 1;
}

canonical_original_code:
short reg_keystroke(int mods, int keysym) {
 unsigned long root = XDefaultRootWindow(disp);
 XSelectInput(disp, root, (1L<<0));
 if (is_modifier(keysym))
  return 0;
 int code = XKeysymToKeycode(disp, keysym);
 XGrabKey(disp, code, mods, root, 0, 1, 1);
 printf("Grabbing mods: %i\n", mods);
 return 1;
}

variable_types: mods int

variable_types: code int


decompiled_code:
void kill_keystrokes()
{
;
}

canonical_decompiled_code:
void func14()
{
;
}

original_code: void kill_keystrokes() {}

canonical_original_code: void kill_keystrokes() {}


main

repo: dorkster/block-breaker

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // rbx
unsigned int v5; // edi
const char **v6; // rcx
const char *v7; // rax
const char *v8; // rdx
char v9; // dl
int v11; // eax

v4 = argv;
v5 = time(0LL);
srand(v5);
if ( argc > 1 )
{
v6 = &argv[(unsigned int)(argc - 2) + 1];
LABEL_3:
while ( 2 )
{
v7 = v4[1];
++v4;
if ( *v7 == 45 )
{
do
{
v8 = v7++;
*v4 = v7;
v9 = v8[1];
if ( !v9 )
{
if ( v4 != v6 )
goto LABEL_3;
goto LABEL_8;
}
}
while ( v9 != 120 );
use_mouse = 0;
if ( v4 != v6 )
continue;
}
break;
}
}
LABEL_8:
if ( !(unsigned int)sys_init() || !(unsigned int)sys_loadfiles() )
return 1;
game_init();
while ( !quit )
{
startTimer = SDL_GetTicks();
sys_input();
game_logic();
draw_everything();
if ( (unsigned int)SDL_Flip(screen) == -1 )
return 1;
v11 = SDL_GetTicks();
endTimer = v11;
deltaTimer = v11 - startTimer;
if ( (unsigned int)(v11 - startTimer) <= 0xF )
SDL_Delay((unsigned int)(startTimer + 16 - v11));
}
sys_cleanup();
return 0;
}

original_code:
int main(int argc, char* argv[]) {
    srand(time(0));
    char c = 0;
    while (--argc > 0 && (*++argv)[0] == '-') {
        while ((c = *++argv[0])) {
            if (c == 'x') {
                use_mouse = false;
                break;
            }
        }
    }
    if(sys_init() == false) return 1;
    if(sys_loadfiles() == false) return 1;
    game_init();
    while(quit == false) {
        startTimer = SDL_GetTicks();
        sys_input();
        game_logic();
        draw_everything();
        if(SDL_Flip(screen) == -1) return 1;
        endTimer = SDL_GetTicks();
        deltaTimer = endTimer - startTimer;
        if(deltaTimer < (1000/60))
            SDL_Delay((1000/60)-deltaTimer);
    }
    sys_cleanup();
}

canonical_original_code:
int main(int argc, char *argv[]) {
    srand(time(0));
    char c = 0;
    while (--argc > 0 && (*++argv)[0] == '-') {
        while ((c = *++argv[0])) {
            if (c == 'x') {
                use_mouse = false;
                break;
            }
        }
    }
    if(sys_init() == false) return 1;
    if(sys_loadfiles() == false) return 1;
    game_init();
    while(quit == false) {
        startTimer = SDL_GetTicks();
        sys_input();
        game_logic();
        draw_everything();
        if(SDL_Flip(screen) == -1) return 1;
        endTimer = SDL_GetTicks();
        deltaTimer = endTimer - startTimer;
        if(deltaTimer < (1000/60))
            SDL_Delay((1000/60)-deltaTimer);
    }
    sys_cleanup();
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c char


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

*(&player + 2) = 0LL;
player = 0x1B80000010ELL;
result = 0x800000064LL;
*(&player + 1) = 0x800000064LL;
*((_DWORD *)&player + 6) = 5;
return result;
}

original_code:
void game_playerinit() {
    player.w = 100;
    player.h = 8;
    player.x = 640/2 - player.w/2;
    player.y = 440;
    player.speed = 0;
    player.score = 0;
    player.lives = 5;
}


decompiled_code:
__int64 game_playermove()
{
int v0; // edx
unsigned int v1; // ecx
int v2; // eax
int v3; // edi
int v4; // eax
__int64 result; // rax
int v6; // eax

v0 = player;
v1 = *((_DWORD *)&player + 2);
if ( use_mouse == 1 )
{
v2 = mouse_x - player - (int)v1 / 2;
*((_DWORD *)&player + 4) = v2;
goto LABEL_9;
}
v2 = *((_DWORD *)&player + 4);
v3 = action_moveright;
if ( action_moveleft == 1 )
{
if ( v2 >= -15 )
{
*((_DWORD *)&player + 4) = --v2;
if ( v3 != 1 )
goto LABEL_6;
goto LABEL_16;
}
}
else if ( !action_moveleft && v2 < 0 )
{
*((_DWORD *)&player + 4) = ++v2;
if ( v3 != 1 )
goto LABEL_9;
LABEL_17:
v6 = v2 + 1;
*((_DWORD *)&player + 4) = v6;
v4 = v0 + v6;
if ( v4 >= 0 )
goto LABEL_10;
goto LABEL_18;
}
if ( action_moveright == 1 )
{
LABEL_16:
if ( v2 > 15 )
goto LABEL_9;
goto LABEL_17;
}
LABEL_6:
if ( !v3 && v2 > 0 )
*((_DWORD *)&player + 4) = --v2;
LABEL_9:
v4 = v0 + v2;
if ( v4 >= 0 )
{
LABEL_10:
LODWORD(player) = v4;
result = v1 + v4;
goto LABEL_11;
}
LABEL_18:
LODWORD(player) = 0;
result = v1;
LABEL_11:
if ( (int)result > 640 )
{
result = 640 - v1;
LODWORD(player) = 640 - v1;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // edx
unsigned int v1; // ecx
int v2; // eax
int v3; // edi
int v4; // eax
__int64 result; // rax
int v6; // eax

v0 = player;
v1 = *((_DWORD *)&player + 2);
if ( use_mouse == 1 )
{
v2 = mouse_x - player - (int)v1 / 2;
*((_DWORD *)&player + 4) = v2;
goto LABEL_9;
}
v2 = *((_DWORD *)&player + 4);
v3 = action_moveright;
if ( action_moveleft == 1 )
{
if ( v2 >= -15 )
{
*((_DWORD *)&player + 4) = --v2;
if ( v3 != 1 )
goto LABEL_6;
goto LABEL_16;
}
}
else if ( !action_moveleft && v2 < 0 )
{
*((_DWORD *)&player + 4) = ++v2;
if ( v3 != 1 )
goto LABEL_9;
LABEL_17:
v6 = v2 + 1;
*((_DWORD *)&player + 4) = v6;
v4 = v0 + v6;
if ( v4 >= 0 )
goto LABEL_10;
goto LABEL_18;
}
if ( action_moveright == 1 )
{
LABEL_16:
if ( v2 > 15 )
goto LABEL_9;
goto LABEL_17;
}
LABEL_6:
if ( !v3 && v2 > 0 )
*((_DWORD *)&player + 4) = --v2;
LABEL_9:
v4 = v0 + v2;
if ( v4 >= 0 )
{
LABEL_10:
LODWORD(player) = v4;
result = v1 + v4;
goto LABEL_11;
}
LABEL_18:
LODWORD(player) = 0;
result = v1;
LABEL_11:
if ( (int)result > 640 )
{
result = 640 - v1;
LODWORD(player) = 640 - v1;
}
return result;
}

original_code:
void game_playermove() {
    if (use_mouse == true) {
        player.speed = mouse_x - player.x - player.w/2;
    } else {
        const int max = 16;
        if(action_moveleft == true && player.speed > -max)
            player.speed -= 1;
        else if(action_moveleft == false && player.speed < 0)
            player.speed += 1;
        if(action_moveright == true && player.speed < max)
            player.speed += 1;
        else if(action_moveright == false && player.speed > 0)
            player.speed -= 1;
    }
    player.x += player.speed;
    if(player.x < 0)
        player.x = 0;
    if(player.x + player.w > 640)
        player.x = 640 - player.w;
}

canonical_original_code:
void game_playermove() {
    if (use_mouse == true) {
        player.speed = mouse_x - player.x - player.w/2;
    } else {
        int max = 16;
        if(action_moveleft == true && player.speed > -max)
            player.speed -= 1;
        else if(action_moveleft == false && player.speed < 0)
            player.speed += 1;
        if(action_moveright == true && player.speed < max)
            player.speed += 1;
        else if(action_moveright == false && player.speed > 0)
            player.speed -= 1;
    }
    player.x += player.speed;
    if(player.x < 0)
        player.x = 0;
    if(player.x + player.w > 640)
        player.x = 640 - player.w;
}


decompiled_code:
__int64 game_ballcreate()
{
int v0; // edx
__int64 result; // rax

game_holdingball = 1;
v0 = *((_DWORD *)&player + 2);
*((_QWORD *)&ball + 1) = 0LL;
ball = player + v0 / 2;
result = (unsigned int)(HIDWORD(player) - 4);
*(&ball + 1) = result;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // edx
__int64 result; // rax

game_holdingball = 1;
v0 = *((_DWORD *)&player + 2);
*((_QWORD *)&ball + 1) = 0LL;
ball = player + v0 / 2;
result = (unsigned int)(HIDWORD(player) - 4);
*(&ball + 1) = result;
return result;
}

original_code:
void game_ballcreate() {
    ball.x = player.x+(player.w/2);
    ball.y = player.y-4;
    ball.xvel = 0;
    ball.yvel = 0;
    game_holdingball = true;
}


decompiled_code:
__int64 game_init()
{
if ( use_mouse == 1 )
SDL_ShowCursor(0LL);
*(&power + 2) = 0;
game_playerinit();
game_blockscreate();
return game_ballcreate();
}

canonical_decompiled_code:
__int64 func4()
{
if ( use_mouse == 1 )
SDL_ShowCursor(0LL);
*(&power + 2) = 0;
func0();
func2();
return func3();
}

original_code:
void game_init() {
    if (use_mouse == true) SDL_ShowCursor(0);
    power.alive = false;
    game_playerinit();
    game_blockscreate();
    game_ballcreate();
}


decompiled_code:
__int64 game_balllaunch()
{
int v0; // edx
__int64 result; // rax

if ( game_holdingball == 1 )
{
game_holdingball = 0;
v0 = *((_DWORD *)&player + 4);
*(&ball + 3) = -4;
result = (unsigned int)(v0 / 2);
*(&ball + 2) = result;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // edx
__int64 result; // rax

if ( game_holdingball == 1 )
{
game_holdingball = 0;
v0 = *((_DWORD *)&player + 4);
*(&ball + 3) = -4;
result = (unsigned int)(v0 / 2);
*(&ball + 2) = result;
}
return result;
}

original_code:
void game_balllaunch() {
    if(game_holdingball == true) {
        game_holdingball = false;
        ball.xvel = player.speed/2;
        ball.yvel = -4;
    }
}


decompiled_code:
__int64 game_ballmove()
{
int v0; // eax
int v1; // edx
__int64 result; // rax

if ( game_holdingball == 1 )
{
v1 = HIDWORD(player) - 4;
v0 = player + *((_DWORD *)&player + 2) / 2;
}
else
{
v0 = ball;
v1 = *(&ball + 1);
}
ball = *(&ball + 2) + v0;
result = (unsigned int)(v1 + *(&ball + 3));
*(&ball + 1) = result;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax
int v1; // edx
__int64 result; // rax

if ( game_holdingball == 1 )
{
v1 = HIDWORD(player) - 4;
v0 = player + *((_DWORD *)&player + 2) / 2;
}
else
{
v0 = ball;
v1 = *(&ball + 1);
}
ball = *(&ball + 2) + v0;
result = (unsigned int)(v1 + *(&ball + 3));
*(&ball + 1) = result;
return result;
}

original_code:
void game_ballmove() {
    if(game_holdingball == true) {
        ball.x = player.x+(player.w/2);
        ball.y = player.y-4;
    }
    ball.x += ball.xvel;
    ball.y += ball.yvel;
}


original_code:
void game_powercreate(int x, int y) {
    if (power.alive == true) return;
    power.x = x;
    power.y = y;
    if (player.w != 100 && rand() % 4 == 0) {
        power.type = POWER_NORMAL;
        power.alive = true;
    } else if (rand() % 16 == 0) {
        power.type = POWER_LARGE;
        power.alive = true;
    } else if (rand() % 8 == 0) {
        power.type = POWER_SMALL;
        power.alive = true;
    }
}

variable_types: x int

variable_types: y int