decompiled_code:
void tunables_load_defaults()
{
tunable_anonymous_enable = 1;
tunable_local_enable = 0;
tunable_pasv_enable = 1;
tunable_port_enable = 1;
tunable_chroot_local_user = 0;
tunable_write_enable = 0;
tunable_anon_upload_enable = 0;
tunable_anon_mkdir_write_enable = 0;
tunable_anon_other_write_enable = 0;
tunable_chown_uploads = 0;
tunable_connect_from_port_20 = 0;
tunable_xferlog_enable = 0;
tunable_dirmessage_enable = 0;
tunable_anon_world_readable_only = 1;
tunable_async_abor_enable = 0;
tunable_ascii_upload_enable = 0;
tunable_ascii_download_enable = 0;
tunable_one_process_model = 0;
tunable_xferlog_std_format = 0;
tunable_pasv_promiscuous = 0;
tunable_deny_email_enable = 0;
tunable_chroot_list_enable = 0;
tunable_setproctitle_enable = 0;
tunable_text_userdb_names = 0;
tunable_ls_recurse_enable = 0;
tunable_log_ftp_protocol = 0;
tunable_guest_enable = 0;
tunable_userlist_enable = 0;
tunable_userlist_deny = 1;
tunable_use_localtime = 0;
tunable_check_shell = 1;
tunable_hide_ids = 0;
tunable_listen = 0;
tunable_port_promiscuous = 0;
tunable_passwd_chroot_enable = 0;
tunable_no_anon_password = 0;
tunable_tcp_wrappers = 0;
tunable_use_sendfile = 1;
tunable_force_dot_files = 0;
tunable_listen_ipv6 = 0;
tunable_dual_log_enable = 0;
tunable_syslog_enable = 0;
tunable_background = 0;
tunable_virtual_use_local_privs = 0;
tunable_session_support = 0;
tunable_download_enable = 1;
tunable_dirlist_enable = 1;
tunable_chmod_enable = 1;
tunable_secure_email_list_enable = 0;
tunable_run_as_launching_user = 0;
tunable_no_log_lock = 0;
tunable_ssl_enable = 0;
tunable_allow_anon_ssl = 0;
tunable_force_local_logins_ssl = 1;
tunable_force_local_data_ssl = 1;
tunable_sslv2 = 0;
tunable_sslv3 = 0;
tunable_tlsv1 = 1;
tunable_tilde_user_enable = 0;
tunable_force_anon_logins_ssl = 0;
tunable_force_anon_data_ssl = 0;
tunable_mdtm_write = 1;
tunable_lock_upload_files = 1;
tunable_pasv_addr_resolve = 0;
tunable_debug_ssl = 0;
tunable_require_cert = 0;
tunable_validate_cert = 0;
tunable_strict_ssl_read_eof = 0;
tunable_strict_ssl_write_shutdown = 0;
tunable_ssl_request_cert = 1;
tunable_delete_failed_uploads = 0;
tunable_implicit_ssl = 0;
tunable_sandbox = 0;
tunable_require_ssl_reuse = 1;
tunable_isolate = 1;
tunable_isolate_network = 1;
tunable_ftp_enable = 1;
tunable_http_enable = 0;
tunable_calc_crc32 = 0;
tunable_accept_timeout = 60;
tunable_connect_timeout = 60;
tunable_local_umask = 63;
tunable_anon_umask = 63;
tunable_ftp_data_port = 20;
tunable_idle_session_timeout = 300;
tunable_data_connection_timeout = 300;
tunable_pasv_min_port = 5001;
tunable_pasv_max_port = 0;
tunable_anon_max_rate = 0;
tunable_local_max_rate = 0;
tunable_listen_port = 21;
tunable_max_clients = 2000;
tunable_file_open_mode = 438;
tunable_max_per_ip = 50;
tunable_trans_chunk_size = 0;
tunable_delay_failed_login = 1;
tunable_delay_successful_login = 0;
tunable_max_login_fails = 3;
tunable_chown_upload_mode = 384;
install_str_setting((__int64)"/usr/share/empty", &tunable_secure_chroot_dir);
install_str_setting((__int64)"ftp", &tunable_ftp_username);
install_str_setting((__int64)"root", &tunable_chown_username);
install_str_setting((__int64)"/var/log/xferlog", &tunable_xferlog_file);
install_str_setting((__int64)"/var/log/flowftpd.log", &tunable_vsftpd_log_file);
install_str_setting((__int64)".message", &tunable_message_file);
install_str_setting((__int64)"nobody", &tunable_nopriv_user);
install_str_setting(0LL, &tunable_ftpd_banner);
install_str_setting((__int64)"/etc/flowftpd.banned_emails", &tunable_banned_email_file);
install_str_setting((__int64)"/etc/flowftpd.chroot_list", &tunable_chroot_list_file);
install_str_setting((__int64)"ftp", &tunable_pam_service_name);
install_str_setting((__int64)"ftp", &tunable_guest_username);
install_str_setting((__int64)"/etc/flowftpd.user_list", &tunable_userlist_file);
install_str_setting(0LL, &tunable_anon_root);
install_str_setting(0LL, &tunable_local_root);
install_str_setting(0LL, &tunable_banner_file);
install_str_setting(0LL, &tunable_pasv_address);
install_str_setting(0LL, &tunable_listen_address);
install_str_setting(0LL, &tunable_user_config_dir);
install_str_setting(0LL, &tunable_listen_address6);
install_str_setting(0LL, &tunable_cmds_allowed);
install_str_setting(0LL, &tunable_cmds_denied);
install_str_setting(0LL, &tunable_hide_file);
install_str_setting(0LL, &tunable_deny_file);
install_str_setting(0LL, &tunable_user_sub_token);
install_str_setting((__int64)"/etc/flowftpd.email_passwords", &tunable_email_password_file);
install_str_setting((__int64)"/usr/share/ssl/certs/flowftpd.pem", &tunable_rsa_cert_file);
install_str_setting(0LL, &tunable_dsa_cert_file);
install_str_setting((__int64)"DES-CBC3-SHA", &tunable_ssl_ciphers);
install_str_setting(0LL, &tunable_rsa_private_key_file);
install_str_setting(0LL, &tunable_dsa_private_key_file);
install_str_setting(0LL, &tunable_ca_certs_file);
install_str_setting(0LL, &tunable_pid_file);
}

canonical_decompiled_code:
void func1()
{
tunable_anonymous_enable = 1;
tunable_local_enable = 0;
tunable_pasv_enable = 1;
tunable_port_enable = 1;
tunable_chroot_local_user = 0;
tunable_write_enable = 0;
tunable_anon_upload_enable = 0;
tunable_anon_mkdir_write_enable = 0;
tunable_anon_other_write_enable = 0;
tunable_chown_uploads = 0;
tunable_connect_from_port_20 = 0;
tunable_xferlog_enable = 0;
tunable_dirmessage_enable = 0;
tunable_anon_world_readable_only = 1;
tunable_async_abor_enable = 0;
tunable_ascii_upload_enable = 0;
tunable_ascii_download_enable = 0;
tunable_one_process_model = 0;
tunable_xferlog_std_format = 0;
tunable_pasv_promiscuous = 0;
tunable_deny_email_enable = 0;
tunable_chroot_list_enable = 0;
tunable_setproctitle_enable = 0;
tunable_text_userdb_names = 0;
tunable_ls_recurse_enable = 0;
tunable_log_ftp_protocol = 0;
tunable_guest_enable = 0;
tunable_userlist_enable = 0;
tunable_userlist_deny = 1;
tunable_use_localtime = 0;
tunable_check_shell = 1;
tunable_hide_ids = 0;
tunable_listen = 0;
tunable_port_promiscuous = 0;
tunable_passwd_chroot_enable = 0;
tunable_no_anon_password = 0;
tunable_tcp_wrappers = 0;
tunable_use_sendfile = 1;
tunable_force_dot_files = 0;
tunable_listen_ipv6 = 0;
tunable_dual_log_enable = 0;
tunable_syslog_enable = 0;
tunable_background = 0;
tunable_virtual_use_local_privs = 0;
tunable_session_support = 0;
tunable_download_enable = 1;
tunable_dirlist_enable = 1;
tunable_chmod_enable = 1;
tunable_secure_email_list_enable = 0;
tunable_run_as_launching_user = 0;
tunable_no_log_lock = 0;
tunable_ssl_enable = 0;
tunable_allow_anon_ssl = 0;
tunable_force_local_logins_ssl = 1;
tunable_force_local_data_ssl = 1;
tunable_sslv2 = 0;
tunable_sslv3 = 0;
tunable_tlsv1 = 1;
tunable_tilde_user_enable = 0;
tunable_force_anon_logins_ssl = 0;
tunable_force_anon_data_ssl = 0;
tunable_mdtm_write = 1;
tunable_lock_upload_files = 1;
tunable_pasv_addr_resolve = 0;
tunable_debug_ssl = 0;
tunable_require_cert = 0;
tunable_validate_cert = 0;
tunable_strict_ssl_read_eof = 0;
tunable_strict_ssl_write_shutdown = 0;
tunable_ssl_request_cert = 1;
tunable_delete_failed_uploads = 0;
tunable_implicit_ssl = 0;
tunable_sandbox = 0;
tunable_require_ssl_reuse = 1;
tunable_isolate = 1;
tunable_isolate_network = 1;
tunable_ftp_enable = 1;
tunable_http_enable = 0;
tunable_calc_crc32 = 0;
tunable_accept_timeout = 60;
tunable_connect_timeout = 60;
tunable_local_umask = 63;
tunable_anon_umask = 63;
tunable_ftp_data_port = 20;
tunable_idle_session_timeout = 300;
tunable_data_connection_timeout = 300;
tunable_pasv_min_port = 5001;
tunable_pasv_max_port = 0;
tunable_anon_max_rate = 0;
tunable_local_max_rate = 0;
tunable_listen_port = 21;
tunable_max_clients = 2000;
tunable_file_open_mode = 438;
tunable_max_per_ip = 50;
tunable_trans_chunk_size = 0;
tunable_delay_failed_login = 1;
tunable_delay_successful_login = 0;
tunable_max_login_fails = 3;
tunable_chown_upload_mode = 384;
func0((__int64)"/usr/share/empty", &tunable_secure_chroot_dir);
func0((__int64)"ftp", &tunable_ftp_username);
func0((__int64)"root", &tunable_chown_username);
func0((__int64)"/var/log/xferlog", &tunable_xferlog_file);
func0((__int64)"/var/log/flowftpd.log", &tunable_vsftpd_log_file);
func0((__int64)".message", &tunable_message_file);
func0((__int64)"nobody", &tunable_nopriv_user);
func0(0LL, &tunable_ftpd_banner);
func0((__int64)"/etc/flowftpd.banned_emails", &tunable_banned_email_file);
func0((__int64)"/etc/flowftpd.chroot_list", &tunable_chroot_list_file);
func0((__int64)"ftp", &tunable_pam_service_name);
func0((__int64)"ftp", &tunable_guest_username);
func0((__int64)"/etc/flowftpd.user_list", &tunable_userlist_file);
func0(0LL, &tunable_anon_root);
func0(0LL, &tunable_local_root);
func0(0LL, &tunable_banner_file);
func0(0LL, &tunable_pasv_address);
func0(0LL, &tunable_listen_address);
func0(0LL, &tunable_user_config_dir);
func0(0LL, &tunable_listen_address6);
func0(0LL, &tunable_cmds_allowed);
func0(0LL, &tunable_cmds_denied);
func0(0LL, &tunable_hide_file);
func0(0LL, &tunable_deny_file);
func0(0LL, &tunable_user_sub_token);
func0((__int64)"/etc/flowftpd.email_passwords", &tunable_email_password_file);
func0((__int64)"/usr/share/ssl/certs/flowftpd.pem", &tunable_rsa_cert_file);
func0(0LL, &tunable_dsa_cert_file);
func0((__int64)"DES-CBC3-SHA", &tunable_ssl_ciphers);
func0(0LL, &tunable_rsa_private_key_file);
func0(0LL, &tunable_dsa_private_key_file);
func0(0LL, &tunable_ca_certs_file);
func0(0LL, &tunable_pid_file);
}

original_code:
void
tunables_load_defaults()
{
  tunable_anonymous_enable = 1;
  tunable_local_enable = 0;
  tunable_pasv_enable = 1;
  tunable_port_enable = 1;
  tunable_chroot_local_user = 0;
  tunable_write_enable = 0;
  tunable_anon_upload_enable = 0;
  tunable_anon_mkdir_write_enable = 0;
  tunable_anon_other_write_enable = 0;
  tunable_chown_uploads = 0;
  tunable_connect_from_port_20 = 0;
  tunable_xferlog_enable = 0;
  tunable_dirmessage_enable = 0;
  tunable_anon_world_readable_only = 1;
  tunable_async_abor_enable = 0;
  tunable_ascii_upload_enable = 0;
  tunable_ascii_download_enable = 0;
  tunable_one_process_model = 0;
  tunable_xferlog_std_format = 0;
  tunable_pasv_promiscuous = 0;
  tunable_deny_email_enable = 0;
  tunable_chroot_list_enable = 0;
  tunable_setproctitle_enable = 0;
  tunable_text_userdb_names = 0;
  tunable_ls_recurse_enable = 0;
  tunable_log_ftp_protocol = 0;
  tunable_guest_enable = 0;
  tunable_userlist_enable = 0;
  tunable_userlist_deny = 1;
  tunable_use_localtime = 0;
  tunable_check_shell = 1;
  tunable_hide_ids = 0;
  tunable_listen = 0;
  tunable_port_promiscuous = 0;
  tunable_passwd_chroot_enable = 0;
  tunable_no_anon_password = 0;
  tunable_tcp_wrappers = 0;
  tunable_use_sendfile = 1;
  tunable_force_dot_files = 0;
  tunable_listen_ipv6 = 0;
  tunable_dual_log_enable = 0;
  tunable_syslog_enable = 0;
  tunable_background = 0;
  tunable_virtual_use_local_privs = 0;
  tunable_session_support = 0;
  tunable_download_enable = 1;
  tunable_dirlist_enable = 1;
  tunable_chmod_enable = 1;
  tunable_secure_email_list_enable = 0;
  tunable_run_as_launching_user = 0;
  tunable_no_log_lock = 0;
  tunable_ssl_enable = 0;
  tunable_allow_anon_ssl = 0;
  tunable_force_local_logins_ssl = 1;
  tunable_force_local_data_ssl = 1;
  tunable_sslv2 = 0;
  tunable_sslv3 = 0;
  tunable_tlsv1 = 1;
  tunable_tilde_user_enable = 0;
  tunable_force_anon_logins_ssl = 0;
  tunable_force_anon_data_ssl = 0;
  tunable_mdtm_write = 1;
  tunable_lock_upload_files = 1;
  tunable_pasv_addr_resolve = 0;
  tunable_debug_ssl = 0;
  tunable_require_cert = 0;
  tunable_validate_cert = 0;
  tunable_strict_ssl_read_eof = 0;
  tunable_strict_ssl_write_shutdown = 0;
  tunable_ssl_request_cert = 1;
  tunable_delete_failed_uploads = 0;
  tunable_implicit_ssl = 0;
  tunable_sandbox = 0;
  tunable_require_ssl_reuse = 1;
  tunable_isolate = 1;
  tunable_isolate_network = 1;
  tunable_ftp_enable = 1;
  tunable_http_enable = 0;
  tunable_calc_crc32 = 0;
  tunable_accept_timeout = 60;
  tunable_connect_timeout = 60;
  tunable_local_umask = 077;
  tunable_anon_umask = 077;
  tunable_ftp_data_port = 20;
  tunable_idle_session_timeout = 300;
  tunable_data_connection_timeout = 300;
  tunable_pasv_min_port = 5001;
  tunable_pasv_max_port = 0;
  tunable_anon_max_rate = 0;
  tunable_local_max_rate = 0;
  tunable_listen_port = 21;
  tunable_max_clients = 2000;
  tunable_file_open_mode = 0666;
  tunable_max_per_ip = 50;
  tunable_trans_chunk_size = 0;
  tunable_delay_failed_login = 1;
  tunable_delay_successful_login = 0;
  tunable_max_login_fails = 3;
  tunable_chown_upload_mode = 0600;
  install_str_setting("/usr/share/empty", &tunable_secure_chroot_dir);
  install_str_setting("ftp", &tunable_ftp_username);
  install_str_setting("root", &tunable_chown_username);
  install_str_setting("/var/log/xferlog", &tunable_xferlog_file);
  install_str_setting("/var/log/" "flowftpd" ".log", &tunable_vsftpd_log_file);
  install_str_setting(".message", &tunable_message_file);
  install_str_setting("nobody", &tunable_nopriv_user);
  install_str_setting(0, &tunable_ftpd_banner);
  install_str_setting("/etc/" "flowftpd" ".banned_emails", &tunable_banned_email_file);
  install_str_setting("/etc/" "flowftpd" ".chroot_list", &tunable_chroot_list_file);
  install_str_setting("ftp", &tunable_pam_service_name);
  install_str_setting("ftp", &tunable_guest_username);
  install_str_setting("/etc/" "flowftpd" ".user_list", &tunable_userlist_file);
  install_str_setting(0, &tunable_anon_root);
  install_str_setting(0, &tunable_local_root);
  install_str_setting(0, &tunable_banner_file);
  install_str_setting(0, &tunable_pasv_address);
  install_str_setting(0, &tunable_listen_address);
  install_str_setting(0, &tunable_user_config_dir);
  install_str_setting(0, &tunable_listen_address6);
  install_str_setting(0, &tunable_cmds_allowed);
  install_str_setting(0, &tunable_cmds_denied);
  install_str_setting(0, &tunable_hide_file);
  install_str_setting(0, &tunable_deny_file);
  install_str_setting(0, &tunable_user_sub_token);
  install_str_setting("/etc/" "flowftpd" ".email_passwords",
                      &tunable_email_password_file);
  install_str_setting("/usr/share/ssl/certs/" "flowftpd" ".pem",
                      &tunable_rsa_cert_file);
  install_str_setting(0, &tunable_dsa_cert_file);
  install_str_setting("DES-CBC3-SHA", &tunable_ssl_ciphers);
  install_str_setting(0, &tunable_rsa_private_key_file);
  install_str_setting(0, &tunable_dsa_private_key_file);
  install_str_setting(0, &tunable_ca_certs_file);
  install_str_setting(0, &tunable_pid_file);
}


main

canonical_name: main

repo: arshadmomen/physics-numaric

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rax
FILE *v4; // rbx
double v5; // r12
double v6; // r13
int v7; // eax
__int64 v8; // rbp
double v9; // xmm0_8
double v10; // [rsp+8h] [rbp-30h] BYREF

v3 = fopen("eval.dat", "r");
if ( argc != 4 )
{
puts("Usage: gsl-histogram xmin xmax n\nComputes a histogram of the data on stdin using n bins from xmin to xmax");
exit(0);
}
v4 = v3;
v5 = atof(argv[1]);
v6 = atof(argv[2]);
v7 = atoi(argv[3]);
v8 = gsl_histogram_alloc(v7);
v9 = v5;
gsl_histogram_set_ranges_uniform(v8, v5, v6);
while ( (unsigned int)_isoc99_fscanf(v4, "%lg", &v10) == 1 )
{
v9 = v10;
gsl_histogram_increment(v8, v10);
}
gsl_histogram_fprintf(stdout, v8, "%g", v9);
gsl_histogram_free(v8);
exit(0);
}

original_code:
int
main ()
{
  srand (time (((void *)0)));
  gen_mat ();
  print_mat ();
  lapacke_wrapper ();
  return 0;
}

canonical_original_code:
int main()
{
  srand (time (((void *)0)));
  gen_mat ();
  print_mat ();
  lapacke_wrapper ();
  return 0;
}

return_type: int


repo: arthurpessoa/udping-port-forward

decompiled_code:
__int64 __fastcall client_cmp(unsigned __int16 *a1, unsigned __int16 *a2)
{
return *a1 - (unsigned int)*a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 *a1, unsigned __int16 *a2)
{
return *a1 - (unsigned int)*a2;
}

original_code:
int client_cmp(client_t *c1, client_t *c2, size_t len)
{
    return c1->id - c2->id;
}

canonical_original_code:
int client_cmp(struct client *c1, struct client *c2, unsigned long len)
{
    return c1->id - c2->id;
}

variable_types: struct client { unsigned short id; struct socket { int fd; int type; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; } *tcp_sock; struct socket *udp_sock; int connected; int to_disconnect; struct timeval { long tv_sec; long tv_usec; } keepalive; char udp2tcp[1024]; int udp2tcp_len; int udp2tcp_state; struct list { void **obj_arr; unsigned long obj_sz; int num_objs; int length; int sort; int (*obj_cmp)(void *, void *, unsigned long); void *(*obj_copy)(void *, void *, unsigned long); void (*obj_free)(void *); } *tcp2udp_q; int tcp2udp_state; struct timeval tcp2udp_timeout; int resend_count; } *

variable_types:
len
unsigned long

user_defined_types: struct client { unsigned short id; struct socket *tcp_sock; struct socket *udp_sock; int connected; int to_disconnect; struct timeval keepalive; char udp2tcp[1024]; int udp2tcp_len; int udp2tcp_state; struct list *tcp2udp_q; int tcp2udp_state; struct timeval tcp2udp_timeout; int resend_count; }

user_defined_types: struct socket { int fd; int type; struct sockaddr_storage addr; unsigned int addr_len; }


decompiled_code:
__int64 __fastcall client_connect_tcp(__int64 a1)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 24) )
return 0xFFFFFFFFLL;
result = sock_connect(*(_QWORD *)(a1 + 8), 0LL);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 24) = 1;
return result;
}

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

if ( *(_DWORD *)(a1 + 24) )
return 0xFFFFFFFFLL;
result = sock_connect(*(_QWORD *)(a1 + 8), 0LL);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 24) = 1;
return result;
}

original_code:
int client_connect_tcp(client_t *c)
{
    if(!c->connected)
    {
        if(sock_connect(c->tcp_sock, 0) == 0)
        {
            c->connected = 1;
            return 0;
        }
    }
    return -1;
}

canonical_original_code:
int client_connect_tcp(struct client *c)
{
    if(!c->connected)
    {
        if(sock_connect(c->tcp_sock, 0) == 0)
        {
            c->connected = 1;
            return 0;
        }
    }
    return -1;
}

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

user_defined_types: struct list { void **obj_arr; unsigned long obj_sz; int num_objs; int length; int sort; int (*obj_cmp)(void *, void *, unsigned long); void *(*obj_copy)(void *, void *, unsigned long); void (*obj_free)(void *); }

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


decompiled_code:
__int64 __fastcall client_disconnect_tcp(__int64 a1)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 24) )
{
result = sock_close(*(_QWORD *)(a1 + 8));
*(_DWORD *)(a1 + 24) = 0;
}
return result;
}

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

if ( *(_DWORD *)(a1 + 24) )
{
result = sock_close(*(_QWORD *)(a1 + 8));
*(_DWORD *)(a1 + 24) = 0;
}
return result;
}

original_code:
void client_disconnect_tcp(client_t *c)
{
    if(c->connected)
    {
        sock_close(c->tcp_sock);
        c->connected = 0;
    }
}

canonical_original_code:
void client_disconnect_tcp(struct client *c)
{
    if(c->connected)
    {
        sock_close(c->tcp_sock);
        c->connected = 0;
    }
}

return_type: void


decompiled_code:
__int64 __fastcall client_disconnect_udp(__int64 a1)
{
return sock_close(*(_QWORD *)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return sock_close(*(_QWORD *)(a1 + 16));
}

original_code:
void client_disconnect_udp(client_t *c)
{
    sock_close(c->udp_sock);
}

canonical_original_code:
void client_disconnect_udp(struct client *c)
{
    sock_close(c->udp_sock);
}


decompiled_code:
void __fastcall client_free(void *ptr)
{
if ( ptr )
{
if ( debug_level > 1 )
{
printf("Freeing client id %d\n", *(unsigned __int16 *)ptr);
printf(" q cnt left: %d\n", *(unsigned int *)(*((_QWORD *)ptr + 135) + 16LL));
}
sock_free(*((_QWORD *)ptr + 1));
sock_free(*((_QWORD *)ptr + 2));
list_free(*((_QWORD *)ptr + 135));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
if ( ptr )
{
if ( debug_level > 1 )
{
printf("Freeing client id %d\n", *(unsigned __int16 *)ptr);
printf(" q cnt left: %d\n", *(unsigned int *)(*((_QWORD *)ptr + 135) + 16LL));
}
sock_free(*((_QWORD *)ptr + 1));
sock_free(*((_QWORD *)ptr + 2));
list_free(*((_QWORD *)ptr + 135));
free(ptr);
}
}

original_code:
void client_free(client_t *c)
{
    if(c)
    {
        if(debug_level >= 2)
        {
            printf("Freeing client id %d\n", c->id);
            printf("  q cnt left: %d\n", ((c->tcp2udp_q)->num_objs));
        }
        sock_free(c->tcp_sock);
        sock_free(c->udp_sock);
        list_free(c->tcp2udp_q);
        free(c);
    }
}

canonical_original_code:
void client_free(struct client *c)
{
    if(c)
    {
        if(debug_level >= 2)
        {
            printf("Freeing client id %d\n", c->id);
            printf("  q cnt left: %d\n", ((c->tcp2udp_q)->num_objs));
        }
        sock_free(c->tcp_sock);
        sock_free(c->udp_sock);
        list_free(c->tcp2udp_q);
        free(c);
    }
}


decompiled_code:
__int64 __fastcall client_recv_udp_msg(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 result; // rax
char v7[152]; // [rsp+8h] [rbp-98h] BYREF

result = msg_recv_msg(*(_QWORD *)(a1 + 16), v7, a2, a3, a4, a5, a6);
if ( (int)result >= 0 )
result = (unsigned int)-((unsigned int)sock_addr_equal(*(_QWORD *)(a1 + 16), v7) == 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 result; // rax
char v7[152]; // [rsp+8h] [rbp-98h] BYREF

result = msg_recv_msg(*(_QWORD *)(a1 + 16), v7, a2, a3, a4, a5, a6);
if ( (int)result >= 0 )
result = (unsigned int)-((unsigned int)sock_addr_equal(*(_QWORD *)(a1 + 16), v7) == 0);
return result;
}

original_code:
int client_recv_udp_msg(client_t *client, char *data, int data_len,
                        uint16_t *id, uint8_t *msg_type, uint16_t *len)
{
    int ret;
    socket_t from;
    ret = msg_recv_msg(client->udp_sock, &from, data, data_len,
                       id, msg_type, len);
    if(ret < 0)
        return ret;
    if(!sock_addr_equal(client->udp_sock, &from))
        return -1;
    return 0;
}

canonical_original_code:
int client_recv_udp_msg(struct client *client, char *data, int data_len, unsigned short *id, unsigned char *msg_type, unsigned short *len)
{
    int ret;
    struct socket from;
    ret = msg_recv_msg(client->udp_sock, &from, data, data_len,
                       id, msg_type, len);
    if(ret < 0)
        return ret;
    if(!sock_addr_equal(client->udp_sock, &from))
        return -1;
    return 0;
}

variable_types:
data
char *

variable_types:
id
unsigned short *

variable_types:
len
unsigned short *

variable_types: ret int

variable_types: struct socket { int fd; int type; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; }


original_code:
int client_got_udp_data(client_t *client, char *data, int data_len,
                        uint8_t msg_type)
{
    int ret;
    int is_resend = 0;
    if(data_len > 1024)
        return -1;
    if((msg_type == 0x05 &&
        client->udp2tcp_state == 2)
       || (msg_type == 0x06 &&
           client->udp2tcp_state == 3))
    {
        memcpy(client->udp2tcp, data, data_len);
        client->udp2tcp_len = data_len;
    }
    else
        is_resend = 1;
    msg_type = (msg_type == 0x05) ? 0x07 : 0x08;
    ret = msg_send_msg(client->udp_sock, client->id, msg_type, ((void *)0), 0);
    if(ret < 0)
        return ret;
    if(is_resend)
        return 1;
    client->udp2tcp_state = client->udp2tcp_state == 2 ?
        3 : 2;
    return 0;
}

canonical_original_code:
int client_got_udp_data(struct client *client, char *data, int data_len, unsigned char msg_type)
{
    int ret;
    int is_resend = 0;
    if(data_len > 1024)
        return -1;
    if((msg_type == 0x05 &&
        client->udp2tcp_state == 2)
       || (msg_type == 0x06 &&
           client->udp2tcp_state == 3))
    {
        memcpy(client->udp2tcp, data, data_len);
        client->udp2tcp_len = data_len;
    }
    else
        is_resend = 1;
    msg_type = (msg_type == 0x05) ? 0x07 : 0x08;
    ret = msg_send_msg(client->udp_sock, client->id, msg_type, ((void *)0), 0);
    if(ret < 0)
        return ret;
    if(is_resend)
        return 1;
    client->udp2tcp_state = client->udp2tcp_state == 2 ?
        3 : 2;
    return 0;
}


decompiled_code:
__int64 __fastcall client_send_tcp_data(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = sock_send(*(_QWORD *)(a1 + 8), a1 + 48, *(unsigned int *)(a1 + 1072));
if ( v1 < 0 )
result = 0xFFFFFFFFLL;
else
result = v1 == 0 ? 0xFFFFFFFE : 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = sock_send(*(_QWORD *)(a1 + 8), a1 + 48, *(unsigned int *)(a1 + 1072));
if ( v1 < 0 )
result = 0xFFFFFFFFLL;
else
result = v1 == 0 ? 0xFFFFFFFE : 0;
return result;
}

original_code:
int client_send_tcp_data(client_t *client)
{
    int ret;
    ret = sock_send(client->tcp_sock, client->udp2tcp, client->udp2tcp_len);
    if(ret < 0)
        return -1;
    else if(ret == 0)
        return -2;
    else
        return 0;
}

canonical_original_code:
int client_send_tcp_data(struct client *client)
{
    int ret;
    ret = sock_send(client->tcp_sock, client->udp2tcp, client->udp2tcp_len);
    if(ret < 0)
        return -1;
    else if(ret == 0)
        return -2;
    else
        return 0;
}


decompiled_code:
__int64 __fastcall client_recv_tcp_data(__int64 a1)
{
int v1; // eax
_DWORD v3[262]; // [rsp+0h] [rbp-418h] BYREF

v1 = sock_recv(*(_QWORD *)(a1 + 8), 0LL, v3, 1024LL);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
if ( !v1 )
return 4294967294LL;
v3[256] = v1;
list_add(*(_QWORD *)(a1 + 1080), v3, 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int v1; // eax
_DWORD v3[262]; // [rsp+0h] [rbp-418h] BYREF

v1 = sock_recv(*(_QWORD *)(a1 + 8), 0LL, v3, 1024LL);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
if ( !v1 )
return 4294967294LL;
v3[256] = v1;
list_add(*(_QWORD *)(a1 + 1080), v3, 1LL);
return 0LL;
}

original_code:
int client_recv_tcp_data(client_t *client)
{
    int ret;
    data_buf_t buf;
    ret = sock_recv(client->tcp_sock, ((void *)0), buf.buf, sizeof(buf.buf));
    if(ret < 0)
        return -1;
    if(ret == 0)
        return -2;
    buf.len = ret;
    list_add(client->tcp2udp_q, &buf, 1);
    return 0;
}

canonical_original_code:
int client_recv_tcp_data(struct client *client)
{
    int ret;
    struct data_buf buf;
    ret = sock_recv(client->tcp_sock, ((void *)0), buf.buf, sizeof(buf.buf));
    if(ret < 0)
        return -1;
    if(ret == 0)
        return -2;
    buf.len = ret;
    list_add(client->tcp2udp_q, &buf, 1);
    return 0;
}

variable_types: struct data_buf { char buf[1024]; int len; }


decompiled_code:
__int64 __fastcall client_send_udp_data(unsigned __int16 *a1)
{
__int64 v2; // rdi
__int64 result; // rax
int v4; // edx
__int64 v5; // rax
int v6; // eax
__int64 v7; // rax

v2 = *((_QWORD *)a1 + 135);
result = *(unsigned int *)(v2 + 16);
if ( (_DWORD)result )
{
if ( *((int *)a1 + 278) > 9 )
return 4294967294LL;
v4 = *((_DWORD *)a1 + 272);
result = 1LL;
if ( (unsigned int)(v4 - 4) > 1 )
{
result = *((unsigned int *)a1 + 269);
if ( (_DWORD)result != 1 )
{
result = 0xFFFFFFFFLL;
if ( v4 <= 4 )
{
if ( v4 == 2 )
{
v7 = list_get_at(v2, 0LL);
result = msg_send_msg(*((_QWORD *)a1 + 2), *a1, 5LL, v7, *(unsigned int *)(v7 + 1024));
if ( (int)result < 0 )
return result;
v6 = 4;
goto LABEL_12;
}
if ( v4 == 3 )
{
v5 = list_get_at(v2, 0LL);
result = msg_send_msg(*((_QWORD *)a1 + 2), *a1, 6LL, v5, *(unsigned int *)(v5 + 1024));
if ( (int)result >= 0 )
{
v6 = 5;
LABEL_12:
*((_DWORD *)a1 + 272) = v6;
gettimeofday((struct timeval *)(a1 + 548), 0LL);
*((_QWORD *)a1 + 137) += *((_DWORD *)a1 + 278) + 1;
return 0LL;
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int16 *a1)
{
__int64 v2; // rdi
__int64 result; // rax
int v4; // edx
__int64 v5; // rax
int v6; // eax
__int64 v7; // rax

v2 = *((_QWORD *)a1 + 135);
result = *(unsigned int *)(v2 + 16);
if ( (_DWORD)result )
{
if ( *((int *)a1 + 278) > 9 )
return 4294967294LL;
v4 = *((_DWORD *)a1 + 272);
result = 1LL;
if ( (unsigned int)(v4 - 4) > 1 )
{
result = *((unsigned int *)a1 + 269);
if ( (_DWORD)result != 1 )
{
result = 0xFFFFFFFFLL;
if ( v4 <= 4 )
{
if ( v4 == 2 )
{
v7 = list_get_at(v2, 0LL);
result = msg_send_msg(*((_QWORD *)a1 + 2), *a1, 5LL, v7, *(unsigned int *)(v7 + 1024));
if ( (int)result < 0 )
return result;
v6 = 4;
goto LABEL_12;
}
if ( v4 == 3 )
{
v5 = list_get_at(v2, 0LL);
result = msg_send_msg(*((_QWORD *)a1 + 2), *a1, 6LL, v5, *(unsigned int *)(v5 + 1024));
if ( (int)result >= 0 )
{
v6 = 5;
LABEL_12:
*((_DWORD *)a1 + 272) = v6;
gettimeofday((struct timeval *)(a1 + 548), 0LL);
*((_QWORD *)a1 + 137) += *((_DWORD *)a1 + 278) + 1;
return 0LL;
}
}
}
}
}
}
return result;
}

original_code:
int client_send_udp_data(client_t *client)
{
    data_buf_t *buf;
    uint8_t msg_type;
    int ret;
    if(((client->tcp2udp_q)->num_objs) == 0)
        return 0;
    if(client->resend_count >= 10)
        return -2;
    if(client->tcp2udp_state == 4 ||
       client->tcp2udp_state == 5 ||
       client->udp2tcp_state == 1)
        return 1;
    switch(client->tcp2udp_state)
    {
        case 2:
        case 4:
            msg_type = 0x05;
            break;
        case 3:
        case 5:
            msg_type = 0x06;
            break;
        default:
            return -1;
    }
    buf = list_get_at(client->tcp2udp_q, 0);
    ret = msg_send_msg(client->udp_sock, client->id, msg_type,
                       buf->buf, buf->len);
    if(ret < 0)
        return ret;
    client->tcp2udp_state = (msg_type == 0x05) ?
        4 : 5;
    gettimeofday(&client->tcp2udp_timeout, ((void *)0));
    client->tcp2udp_timeout.tv_sec += (client->resend_count+1)*1;
    return 0;
}

canonical_original_code:
int client_send_udp_data(struct client *client)
{
    struct data_buf *buf;
    unsigned char msg_type;
    int ret;
    if(((client->tcp2udp_q)->num_objs) == 0)
        return 0;
    if(client->resend_count >= 10)
        return -2;
    if(client->tcp2udp_state == 4 ||
       client->tcp2udp_state == 5 ||
       client->udp2tcp_state == 1)
        return 1;
    switch(client->tcp2udp_state)
    {
        case 2:
        case 4:
            msg_type = 0x05;
            break;
        case 3:
        case 5:
            msg_type = 0x06;
            break;
        default:
            return -1;
    }
    buf = list_get_at(client->tcp2udp_q, 0);
    ret = msg_send_msg(client->udp_sock, client->id, msg_type,
                       buf->buf, buf->len);
    if(ret < 0)
        return ret;
    client->tcp2udp_state = (msg_type == 0x05) ?
        4 : 5;
    gettimeofday(&client->tcp2udp_timeout, ((void *)0));
    client->tcp2udp_timeout.tv_sec += (client->resend_count+1)*1;
    return 0;
}

variable_types: struct data_buf { char buf[1024]; int len; } *


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

if ( a2 == 7 )
{
result = 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 1088) == 4 )
{
list_delete_at(*(_QWORD *)(a1 + 1080), 0LL);
*(_DWORD *)(a1 + 1088) = 3;
*(_DWORD *)(a1 + 1112) = 0;
result = 0LL;
}
}
else if ( a2 == 8 )
{
if ( *(_DWORD *)(a1 + 1088) == 5 )
{
list_delete_at(*(_QWORD *)(a1 + 1080), 0LL);
*(_DWORD *)(a1 + 1088) = 2;
*(_DWORD *)(a1 + 1112) = 0;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a2 == 7 )
{
result = 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 1088) == 4 )
{
list_delete_at(*(_QWORD *)(a1 + 1080), 0LL);
*(_DWORD *)(a1 + 1088) = 3;
*(_DWORD *)(a1 + 1112) = 0;
result = 0LL;
}
}
else if ( a2 == 8 )
{
if ( *(_DWORD *)(a1 + 1088) == 5 )
{
list_delete_at(*(_QWORD *)(a1 + 1080), 0LL);
*(_DWORD *)(a1 + 1088) = 2;
*(_DWORD *)(a1 + 1112) = 0;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int client_got_ack(client_t *client, uint8_t ack_type)
{
    if(ack_type == 0x07 && client->tcp2udp_state == 4)
    {
        list_delete_at(client->tcp2udp_q, 0);
        client->tcp2udp_state = 3;
        client->resend_count = 0;
        return 0;
    }
    if(ack_type == 0x08 && client->tcp2udp_state == 5)
    {
        list_delete_at(client->tcp2udp_q, 0);
        client->tcp2udp_state = 2;
        client->resend_count = 0;
        return 0;
    }
    return -1;
}

canonical_original_code:
int client_got_ack(struct client *client, unsigned char ack_type)
{
    if(ack_type == 0x07 && client->tcp2udp_state == 4)
    {
        list_delete_at(client->tcp2udp_q, 0);
        client->tcp2udp_state = 3;
        client->resend_count = 0;
        return 0;
    }
    if(ack_type == 0x08 && client->tcp2udp_state == 5)
    {
        list_delete_at(client->tcp2udp_q, 0);
        client->tcp2udp_state = 2;
        client->resend_count = 0;
        return 0;
    }
    return -1;
}


decompiled_code:
__int64 __fastcall client_send_hello(__int64 a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
return msg_send_hello(*(_QWORD *)(a1 + 16), a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
return msg_send_hello(*(_QWORD *)(a1 + 16), a2, a3, a4);
}

original_code:
int client_send_hello(client_t *client, char *host, char *port,
                      uint16_t req_id)
{
    return msg_send_hello(client->udp_sock, host, port, req_id);
}

canonical_original_code:
int client_send_hello(struct client *client, char *host, char *port, unsigned short req_id)
{
    return msg_send_hello(client->udp_sock, host, port, req_id);
}

variable_types:
host
char *

variable_types:
port
char *


decompiled_code:
__int64 __fastcall client_send_helloack(unsigned __int16 *a1, __int16 a2)
{
__int16 v3[6]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = _bswap_16(a2);
return msg_send_msg(*((_QWORD *)a1 + 2), *a1, 3LL, v3, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int16 *a1, __int16 a2)
{
__int16 v3[6]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = func0(a2);
return msg_send_msg(*((_QWORD *)a1 + 2), *a1, 3LL, v3, 2LL);
}

original_code:
int client_send_helloack(client_t *client, uint16_t req_id)
{
    req_id = htons(req_id);
    return msg_send_msg(client->udp_sock, client->id, 0x03,
                        (char *)&req_id, sizeof(req_id));
}

canonical_original_code:
int client_send_helloack(struct client *client, unsigned short req_id)
{
    req_id = htons(req_id);
    return msg_send_msg(client->udp_sock, client->id, 0x03,
                        (char *)&req_id, sizeof(req_id));
}


decompiled_code:
__int64 __fastcall client_got_helloack(__int64 a1)
{
if ( *(_DWORD *)(a1 + 1076) == 1 )
*(_DWORD *)(a1 + 1076) = 2;
return 0LL;
}

original_code:
int client_got_helloack(client_t *client)
{
    if(client->udp2tcp_state == 1)
        client->udp2tcp_state = 2;
    return 0;
}

canonical_original_code:
int client_got_helloack(struct client *client)
{
    if(client->udp2tcp_state == 1)
        client->udp2tcp_state = 2;
    return 0;
}


decompiled_code:
__int64 __fastcall client_send_goodbye(unsigned __int16 *a1)
{
return msg_send_msg(*((_QWORD *)a1 + 2), *a1, 1LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned __int16 *a1)
{
return msg_send_msg(*((_QWORD *)a1 + 2), *a1, 1LL, 0LL, 0LL);
}

original_code:
int client_send_goodbye(client_t *client)
{
    return msg_send_msg(client->udp_sock, client->id, 0x01,
                        ((void *)0), 0);
}

canonical_original_code:
int client_send_goodbye(struct client *client)
{
    return msg_send_msg(client->udp_sock, client->id, 0x01,
                        ((void *)0), 0);
}


decompiled_code:
__int64 __fastcall client_check_and_resend(unsigned __int16 *a1, __int64 a2, __int64 a3)
{
unsigned int v3; // ecx
__int64 v5; // rax
__int64 v6; // rdx

v3 = 0;
if ( (unsigned int)(*((_DWORD *)a1 + 272) - 4) > 1 )
return 0LL;
v5 = *((_QWORD *)a1 + 137);
if ( v5 == a2 )
{
if ( *((_QWORD *)a1 + 138) >= a3 )
return v3;
LABEL_7:
v6 = (unsigned int)(*((_DWORD *)a1 + 278) + 1);
*((_DWORD *)a1 + 278) = v6;
if ( debug_level > 1 )
printf("client(%d): resending data, count %d\n", *a1, v6);
return (unsigned int)client_send_udp_data(a1);
}
v3 = 0;
if ( v5 < a2 )
goto LABEL_7;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned __int16 *a1, __int64 a2, __int64 a3)
{
unsigned int v3; // ecx
__int64 v5; // rax
__int64 v6; // rdx

v3 = 0;
if ( (unsigned int)(*((_DWORD *)a1 + 272) - 4) > 1 )
return 0LL;
v5 = *((_QWORD *)a1 + 137);
if ( v5 == a2 )
{
if ( *((_QWORD *)a1 + 138) >= a3 )
return v3;
LABEL_7:
v6 = (unsigned int)(*((_DWORD *)a1 + 278) + 1);
*((_DWORD *)a1 + 278) = v6;
if ( debug_level > 1 )
printf("client(%d): resending data, count %d\n", *a1, v6);
return (unsigned int)func10(a1);
}
v3 = 0;
if ( v5 < a2 )
goto LABEL_7;
return v3;
}

original_code:
int client_check_and_resend(client_t *client, struct timeval curr_tv)
{
    if((client->tcp2udp_state == 4 ||
        client->tcp2udp_state == 5)
       && (((&curr_tv)->tv_sec == (&client->tcp2udp_timeout)->tv_sec) ? ((&curr_tv)->tv_usec > (&client->tcp2udp_timeout)->tv_usec) : ((&curr_tv)->tv_sec > (&client->tcp2udp_timeout)->tv_sec)))
    {
        client->resend_count++;
        if(debug_level >= 2)
            printf("client(%d): resending data, count %d\n",
                   ((client)->id), client->resend_count);
        return client_send_udp_data(client);
    }
    return 0;
}

canonical_original_code:
int client_check_and_resend(struct client *client, struct timeval curr_tv)
{
    if((client->tcp2udp_state == 4 ||
        client->tcp2udp_state == 5)
       && (((&curr_tv)->tv_sec == (&client->tcp2udp_timeout)->tv_sec) ? ((&curr_tv)->tv_usec > (&client->tcp2udp_timeout)->tv_usec) : ((&curr_tv)->tv_sec > (&client->tcp2udp_timeout)->tv_sec)))
    {
        client->resend_count++;
        if(debug_level >= 2)
            printf("client(%d): resending data, count %d\n",
                   ((client)->id), client->resend_count);
        return client_send_udp_data(client);
    }
    return 0;
}


decompiled_code:
int __fastcall client_reset_keepalive(__m128i *a1)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

result = gettimeofday(&v2, 0LL);
v2.tv_sec += 421LL;
a1[2] = _mm_loadu_si128((const __m128i *)&v2);
return result;
}

canonical_decompiled_code:
int __fastcall func17(__m128i *a1)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

result = gettimeofday(&v2, 0LL);
v2.tv_sec += 421LL;
a1[2] = _mm_loadu_si128((const __m128i *)&v2);
return result;
}

original_code:
void client_reset_keepalive(client_t *client)
{
    struct timeval curr;
    gettimeofday(&curr, ((void *)0));
    curr.tv_sec += (7*60+1);
    memcpy(&client->keepalive, &curr, sizeof(struct timeval));
}

canonical_original_code:
void client_reset_keepalive(struct client *client)
{
    struct timeval curr;
    gettimeofday(&curr, ((void *)0));
    curr.tv_sec += (7*60+1);
    memcpy(&client->keepalive, &curr, sizeof(struct timeval));
}

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


decompiled_code:
__int64 __fastcall client_timed_out(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 32);
LOBYTE(result) = v3 < a2;
if ( v3 == a2 )
LOBYTE(result) = *(_QWORD *)(a1 + 40) < a3;
return (unsigned __int8)result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 32);
LOBYTE(result) = v3 < a2;
if ( v3 == a2 )
LOBYTE(result) = *(_QWORD *)(a1 + 40) < a3;
return (unsigned __int8)result;
}

original_code:
int client_timed_out(client_t *client, struct timeval curr_tv)
{
    if((((&curr_tv)->tv_sec == (&client->keepalive)->tv_sec) ? ((&curr_tv)->tv_usec > (&client->keepalive)->tv_usec) : ((&curr_tv)->tv_sec > (&client->keepalive)->tv_sec)))
        return 1;
    else
        return 0;
}

canonical_original_code:
int client_timed_out(struct client *client, struct timeval curr_tv)
{
    if((((&curr_tv)->tv_sec == (&client->keepalive)->tv_sec) ? ((&curr_tv)->tv_usec > (&client->keepalive)->tv_usec) : ((&curr_tv)->tv_sec > (&client->keepalive)->tv_sec)))
        return 1;
    else
        return 0;
}


decompiled_code:
__int64 __fastcall client_check_and_send_keepalive(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

result = client_timed_out((__int64)a1, a2, a3);
if ( (_DWORD)result )
{
a1[4] = a2 + 60;
a1[5] = a3;
result = msg_send_msg(a1[2], *(unsigned __int16 *)a1, 4LL, 0LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

result = func18((__int64)a1, a2, a3);
if ( (_DWORD)result )
{
a1[4] = a2 + 60;
a1[5] = a3;
result = msg_send_msg(a1[2], *(unsigned __int16 *)a1, 4LL, 0LL, 0LL);
}
return result;
}

original_code:
int client_check_and_send_keepalive(client_t *client, struct timeval curr_tv)
{
    if(client_timed_out(client, curr_tv))
    {
        curr_tv.tv_sec += 60;
        memcpy(&client->keepalive, &curr_tv, sizeof(struct timeval));
        return msg_send_msg(client->udp_sock, client->id, 0x04,
                            ((void *)0), 0);
    }
    return 0;
}

canonical_original_code:
int client_check_and_send_keepalive(struct client *client, struct timeval curr_tv)
{
    if(client_timed_out(client, curr_tv))
    {
        curr_tv.tv_sec += 60;
        memcpy(&client->keepalive, &curr_tv, sizeof(struct timeval));
        return msg_send_msg(client->udp_sock, client->id, 0x04,
                            ((void *)0), 0);
    }
    return 0;
}


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

if ( *(_DWORD *)(a1 + 16) <= a2 || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

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

if ( *(_DWORD *)(a1 + 16) <= a2 || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

original_code:
void *list_get_at(list_t *list, int i)
{
    if(i >= list->num_objs || i < 0)
        return ((void *)0);
    return list->obj_arr[i];
}

canonical_original_code:
void *list_get_at(struct list *list, int i)
{
    if(i >= list->num_objs || i < 0)
        return ((void *)0);
    return list->obj_arr[i];
}

variable_types: struct list { void **obj_arr; unsigned long obj_sz; int num_objs; int length; int sort; int (*obj_cmp)(void *, void *, unsigned long); void *(*obj_copy)(void *, void *, unsigned long); void (*obj_free)(void *); } *

variable_types: i int

return_type: void *


decompiled_code:
__int64 __fastcall list_get_index(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
unsigned int v3; // er13

if ( *(int *)(a1 + 16) <= 0 )
return (unsigned int)-1;
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( !(*(unsigned int (__fastcall **)(_QWORD, __int64, _QWORD))(a1 + 32))(
*(_QWORD *)(*(_QWORD *)a1 + 8 * v2),
a2,
*(_QWORD *)(a1 + 8)) )
break;
if ( *(_DWORD *)(a1 + 16) <= (int)++v2 )
return (unsigned int)-1;
}
return v3;
}

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

if ( *(int *)(a1 + 16) <= 0 )
return (unsigned int)-1;
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( !(*(unsigned int (__fastcall **)(_QWORD, __int64, _QWORD))(a1 + 32))(
*(_QWORD *)(*(_QWORD *)a1 + 8 * v2),
a2,
*(_QWORD *)(a1 + 8)) )
break;
if ( *(_DWORD *)(a1 + 16) <= (int)++v2 )
return (unsigned int)-1;
}
return v3;
}

original_code:
int list_get_index(list_t *list, void *obj)
{
    int i;
    for(i = 0; i < list->num_objs; i++)
    {
        if(list->obj_cmp(list->obj_arr[i], obj, list->obj_sz) == 0)
            return i;
    }
    return -1;
}

canonical_original_code:
int list_get_index(struct list *list, void *obj)
{
    int i;
    for(i = 0; i < list->num_objs; i++)
    {
        if(list->obj_cmp(list->obj_arr[i], obj, list->obj_sz) == 0)
            return i;
    }
    return -1;
}

variable_types:
obj
void *


decompiled_code:
__int64 __fastcall list_get(_QWORD *a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = list_get_index((__int64)a1, a2);
if ( v2 == -1 )
result = 0LL;
else
result = *(_QWORD *)(*a1 + 8LL * v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = func1((__int64)a1, a2);
if ( v2 == -1 )
result = 0LL;
else
result = *(_QWORD *)(*a1 + 8LL * v2);
return result;
}

original_code:
void *list_get(list_t *list, void *obj)
{
    int i;
    i = list_get_index(list, obj);
    if(i == -1)
        return ((void *)0);
    return list->obj_arr[i];
}

canonical_original_code:
void *list_get(struct list *list, void *obj)
{
    int i;
    i = list_get_index(list, obj);
    if(i == -1)
        return ((void *)0);
    return list->obj_arr[i];
}


original_code:
void *list_add(list_t *list, void *obj, int copy)
{
    void *o;
    void **new_arr;
    void *temp;
    int i;
    o = list_get(list, obj);
    if(o)
        return o;
    if(copy == 1)
    {
        o = malloc(list->obj_sz);
        if(o == ((void *)0))
            return ((void *)0);
        list->obj_copy(o, obj, list->obj_sz);
    }
    else
    {
        o = obj;
    }
    if(list->num_objs == list->length)
    {
        new_arr = realloc(list->obj_arr, list->length * 2 * sizeof(void *));
        if(!new_arr)
        {
            list->obj_free(o);
            return ((void *)0);
        }
        list->obj_arr = new_arr;
        list->length *= 2;
    }
    list->obj_arr[list->num_objs++] = o;
    if(list->sort == 1)
    {
        for(i = list->num_objs-1; i > 0; i--)
        {
            if(list->obj_cmp(list->obj_arr[i-1], list->obj_arr[i],
                             list->obj_sz) > 0)
            {
                temp = list->obj_arr[i-1];
                list->obj_arr[i-1] = list->obj_arr[i];
                list->obj_arr[i] = temp;
            }
            else
                break;
        }
    }
    return o;
}

canonical_original_code:
void *list_add(struct list *list, void *obj, int copy)
{
    void *o;
    void **new_arr;
    void *temp;
    int i;
    o = list_get(list, obj);
    if(o)
        return o;
    if(copy == 1)
    {
        o = malloc(list->obj_sz);
        if(o == ((void *)0))
            return ((void *)0);
        list->obj_copy(o, obj, list->obj_sz);
    }
    else
    {
        o = obj;
    }
    if(list->num_objs == list->length)
    {
        new_arr = realloc(list->obj_arr, list->length * 2 * sizeof(void *));
        if(!new_arr)
        {
            list->obj_free(o);
            return ((void *)0);
        }
        list->obj_arr = new_arr;
        list->length *= 2;
    }
    list->obj_arr[list->num_objs++] = o;
    if(list->sort == 1)
    {
        for(i = list->num_objs-1; i > 0; i--)
        {
            if(list->obj_cmp(list->obj_arr[i-1], list->obj_arr[i],
                             list->obj_sz) > 0)
            {
                temp = list->obj_arr[i-1];
                list->obj_arr[i-1] = list->obj_arr[i];
                list->obj_arr[i] = temp;
            }
            else
                break;
        }
    }
    return o;
}

variable_types: copy int

variable_types:
o
void *

variable_types:
temp
void *


decompiled_code:
__int64 __fastcall list_action(__int64 a1, __int64 (__fastcall *a2)(_QWORD))
{
__int64 v2; // rbx
__int64 result; // rax

if ( *(int *)(a1 + 16) > 0 )
{
v2 = 0LL;
do
result = a2(*(_QWORD *)(*(_QWORD *)a1 + 8 * v2++));
while ( *(_DWORD *)(a1 + 16) > (int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 (__fastcall *a2)(_QWORD))
{
__int64 v2; // rbx
__int64 result; // rax

if ( *(int *)(a1 + 16) > 0 )
{
v2 = 0LL;
do
result = a2(*(_QWORD *)(*(_QWORD *)a1 + 8 * v2++));
while ( *(_DWORD *)(a1 + 16) > (int)v2 );
}
return result;
}

original_code:
void list_action(list_t *list, void (*action)(void *))
{
    int i;
    for(i = 0; i < list->num_objs; i++)
        action(list->obj_arr[i]);
}

canonical_original_code:
void list_action(struct list *list, void (*action)(void *))
{
    int i;
    for(i = 0; i < list->num_objs; i++)
        action(list->obj_arr[i]);
}

variable_types:
action
void (*)(void *)


original_code:
void list_delete_at(list_t *list, int i)
{
    if(i >= list->num_objs || i < 0)
        return;
    list->obj_free(list->obj_arr[i]);
    for(; i < list->num_objs - 1; i++)
        list->obj_arr[i] = list->obj_arr[i+1];
    list->obj_arr[i] = ((void *)0);
    list->num_objs--;
}

canonical_original_code:
void list_delete_at(struct list *list, int i)
{
    if(i >= list->num_objs || i < 0)
        return;
    list->obj_free(list->obj_arr[i]);
    for(; i < list->num_objs - 1; i++)
        list->obj_arr[i] = list->obj_arr[i+1];
    list->obj_arr[i] = ((void *)0);
    list->num_objs--;
}


decompiled_code:
void __fastcall list_delete(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = list_get_index(a1, a2);
list_delete_at(a1, v2);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = func1(a1, a2);
func5(a1, v2);
}

original_code:
void list_delete(list_t *list, void *obj)
{
    list_delete_at(list, list_get_index(list, obj));
}

canonical_original_code:
void list_delete(struct list *list, void *obj)
{
    list_delete_at(list, list_get_index(list, obj));
}


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

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

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

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

original_code:
void list_free(list_t *list)
{
    int i;
    for(i = 0; i < list->num_objs; i++)
        list->obj_free(list->obj_arr[i]);
    free(list->obj_arr);
    free(list);
}

canonical_original_code:
void list_free(struct list *list)
{
    int i;
    for(i = 0; i < list->num_objs; i++)
        list->obj_free(list->obj_arr[i]);
    free(list->obj_arr);
    free(list);
}


isnum

decompiled_code:
__int64 __fastcall isnum(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const unsigned __int16 *v3; // rax

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1;
v3 = *_ctype_b_loc();
while ( (v3[v1] & 0x800) != 0 )
{
v1 = *++v2;
if ( !*v2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const unsigned __int16 *v3; // rax

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1;
v3 = *_ctype_b_loc();
while ( (v3[v1] & 0x800) != 0 )
{
v1 = *++v2;
if ( !*v2 )
return 1LL;
}
return 0LL;
}

original_code:
static inline int isnum(char *s)
{
    for(; *s != '\0'; s++)
    {
        if(!((*__ctype_b_loc ())[(int) (((int)*s))] & (unsigned short int) _ISdigit))
            return 0;
    }
    return 1;
}

canonical_original_code:
static inline int isnum(char *s)
{
    for(; *s != '\0'; s++)
    {
        if(!((*__ctype_b_loc ())[(int) (((int)*s))] & (unsigned short) _ISdigit))
            return 0;
    }
    return 1;
}

variable_types:
s
char *


decompiled_code:
void __fastcall acl_free(void *ptr)
{
if ( *(_QWORD *)ptr )
sock_free();
if ( *((_QWORD *)ptr + 1) )
sock_free();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( *(_QWORD *)ptr )
sock_free();
if ( *((_QWORD *)ptr + 1) )
sock_free();
free(ptr);
}

original_code:
void acl_free(acl_t *acl)
{
    if(acl->src)
        sock_free(acl->src);
    if(acl->dst)
        sock_free(acl->dst);
    free(acl);
}

canonical_original_code:
void acl_free(struct acl *acl)
{
    if(acl->src)
        sock_free(acl->src);
    if(acl->dst)
        sock_free(acl->dst);
    free(acl);
}

variable_types: struct acl { struct socket { int fd; int type; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; } *src; struct socket *dst; int action; } *

user_defined_types: struct acl { struct socket *src; struct socket *dst; int action; }


decompiled_code:
__int64 __fastcall acl_action(__int64 *a1, __int64 a2, __int16 a3, __int64 a4, __int16 a5)
{
__int64 v8; // r12
unsigned int v9; // eax
__int64 v10; // rax
unsigned int v11; // er12
__int64 v12; // rbp
__int64 v13; // r12
unsigned int v14; // eax
__int64 v15; // r13
__int16 v16; // ax
__int16 v18; // ax

v8 = *a1;
v9 = sock_get_ipver(*a1);
v10 = sock_create(a2, 0LL, v9, *(unsigned int *)(v8 + 4), 0LL, 0LL);
v11 = 0;
if ( v10 )
{
v12 = v10;
v13 = a1[1];
v14 = sock_get_ipver(v13);
v15 = sock_create(a4, 0LL, v14, *(unsigned int *)(v13 + 4), 0LL, 0LL);
v11 = 0;
if ( v15 )
{
v16 = sock_get_port(*a1);
if ( !v16 || v16 == a3 )
{
v18 = sock_get_port(a1[1]);
if ( !v18 || (v11 = 0, v18 == a5) )
{
v11 = sock_isaddrany(*a1);
if ( v11 || !(unsigned int)sock_ipaddr_cmp(*a1, v12) )
{
v11 = sock_isaddrany(a1[1]);
if ( v11 || !(unsigned int)sock_ipaddr_cmp(a1[1], v15) )
v11 = *((_DWORD *)a1 + 4);
}
}
}
}
sock_free(v12);
if ( v15 )
sock_free(v15);
}
return v11;
}

original_code:
int acl_action(acl_t *acl, char *src, uint16_t sport, char *dst, uint16_t dport)
{
    socket_t *s = ((void *)0);
    socket_t *d = ((void *)0);
    uint16_t p;
    int ret;
    ret = 0;
    s = sock_create(src, ((void *)0), sock_get_ipver(acl->src),
                    ((acl->src)->type), 0, 0);
    if(s == ((void *)0))
        goto done;
    d = sock_create(dst, ((void *)0), sock_get_ipver(acl->dst),
                    ((acl->dst)->type), 0, 0);
    if(d == ((void *)0))
        goto done;
    p = sock_get_port(acl->src);
    if(p != 0 && p != sport)
        goto done;
    p = sock_get_port(acl->dst);
    if(p != 0 && p != dport)
        goto done;
    if(!sock_isaddrany(acl->src) && sock_ipaddr_cmp(acl->src, s) != 0)
        goto done;
    if(!sock_isaddrany(acl->dst) && sock_ipaddr_cmp(acl->dst, d) != 0)
        goto done;
    ret = acl->action;
  done:
    if(s)
        sock_free(s);
    if(d)
        sock_free(d);
    return ret;
}

canonical_original_code:
int acl_action(struct acl *acl, char *src, unsigned short sport, char *dst, unsigned short dport)
{
    struct socket *s = ((void *)0);
    struct socket *d = ((void *)0);
    unsigned short p;
    int ret;
    ret = 0;
    s = sock_create(src, ((void *)0), sock_get_ipver(acl->src),
                    ((acl->src)->type), 0, 0);
    if(s == ((void *)0))
        goto done;
    d = sock_create(dst, ((void *)0), sock_get_ipver(acl->dst),
                    ((acl->dst)->type), 0, 0);
    if(d == ((void *)0))
        goto done;
    p = sock_get_port(acl->src);
    if(p != 0 && p != sport)
        goto done;
    p = sock_get_port(acl->dst);
    if(p != 0 && p != dport)
        goto done;
    if(!sock_isaddrany(acl->src) && sock_ipaddr_cmp(acl->src, s) != 0)
        goto done;
    if(!sock_isaddrany(acl->dst) && sock_ipaddr_cmp(acl->dst, d) != 0)
        goto done;
    ret = acl->action;
  done:
    if(s)
        sock_free(s);
    if(d)
        sock_free(d);
    return ret;
}

variable_types:
src
char *

variable_types:
sport
unsigned short

variable_types:
dst
char *

variable_types:
dport
unsigned short

variable_types: struct socket { int fd; int type; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; } *

variable_types:
p
unsigned short


decompiled_code:
int __fastcall acl_print(_QWORD *a1)
{
unsigned __int16 v1; // ax
unsigned __int16 v2; // ax
int v3; // eax
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

if ( !(unsigned int)sock_isaddrany(*a1) )
{
sock_get_addrstr(*a1, v5, 55LL);
printf("s=%s,", v5);
}
v1 = sock_get_port(*a1);
if ( v1 )
printf("sp=%hu,", v1);
if ( !(unsigned int)sock_isaddrany(a1[1]) )
{
sock_get_addrstr(a1[1], v5, 55LL);
printf("d=%s,", v5);
}
v2 = sock_get_port(a1[1]);
if ( v2 )
printf("dp=%hu,", v2);
v3 = *((_DWORD *)a1 + 4);
if ( v3 == 1 )
return puts("a=deny");
if ( v3 == 2 )
return puts("a=allow");
return puts("a=??");
}

canonical_decompiled_code:
int __fastcall func4(_QWORD *a1)
{
unsigned __int16 v1; // ax
unsigned __int16 v2; // ax
int v3; // eax
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

if ( !(unsigned int)sock_isaddrany(*a1) )
{
sock_get_addrstr(*a1, v5, 55LL);
printf("s=%s,", v5);
}
v1 = sock_get_port(*a1);
if ( v1 )
printf("sp=%hu,", v1);
if ( !(unsigned int)sock_isaddrany(a1[1]) )
{
sock_get_addrstr(a1[1], v5, 55LL);
printf("d=%s,", v5);
}
v2 = sock_get_port(a1[1]);
if ( v2 )
printf("dp=%hu,", v2);
v3 = *((_DWORD *)a1 + 4);
if ( v3 == 1 )
return puts("a=deny");
if ( v3 == 2 )
return puts("a=allow");
return puts("a=??");
}

original_code:
void acl_print(acl_t *acl)
{
    char addr_str[(46 + 9)];
    int len;
    uint16_t port;
    len = sizeof(addr_str);
    if(!sock_isaddrany(acl->src))
    {
        sock_get_addrstr(acl->src, addr_str, len);
        printf("s=%s,", addr_str);
    }
    if((port = sock_get_port(acl->src)) != 0)
        printf("sp=%hu,", port);
    if(!sock_isaddrany(acl->dst))
    {
        sock_get_addrstr(acl->dst, addr_str, len);
        printf("d=%s,", addr_str);
    }
    if((port = sock_get_port(acl->dst)) != 0)
        printf("dp=%hu,", port);
    switch(acl->action)
    {
        case 2:
            printf("a=allow\n");
            break;
        case 1:
            printf("a=deny\n");
            break;
        default:
            printf("a=??\n");
            break;
    }
}

canonical_original_code:
void acl_print(struct acl *acl)
{
    char addr_str[-1];
    int len;
    unsigned short port;
    len = sizeof(addr_str);
    if(!sock_isaddrany(acl->src))
    {
        sock_get_addrstr(acl->src, addr_str, len);
        printf("s=%s,", addr_str);
    }
    if((port = sock_get_port(acl->src)) != 0)
        printf("sp=%hu,", port);
    if(!sock_isaddrany(acl->dst))
    {
        sock_get_addrstr(acl->dst, addr_str, len);
        printf("d=%s,", addr_str);
    }
    if((port = sock_get_port(acl->dst)) != 0)
        printf("dp=%hu,", port);
    switch(acl->action)
    {
        case 2:
            printf("a=allow\n");
            break;
        case 1:
            printf("a=deny\n");
            break;
        default:
            printf("a=??\n");
            break;
    }
}

variable_types: len int

variable_types:
port
unsigned short


decompiled_code:
__int16 __fastcall msg_init_header(__int64 a1, __int16 a2, char a3, __int16 a4)
{
__int16 result; // ax

*(_WORD *)a1 = _bswap_16(a2);
*(_BYTE *)(a1 + 2) = a3;
result = _bswap_16(a4);
*(_WORD *)(a1 + 3) = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func2(__int64 a1, __int16 a2, char a3, __int16 a4)
{
__int16 result; // ax

*(_WORD *)a1 = func1(a2);
*(_BYTE *)(a1 + 2) = a3;
result = func1(a4);
*(_WORD *)(a1 + 3) = result;
return result;
}

original_code:
static inline void msg_init_header(msg_hdr_t *hdr, uint16_t client_id,
                                   uint8_t type, uint16_t len)
{
    hdr->client_id = htons(client_id);
    hdr->type = type;
    hdr->length = htons(len);
}

canonical_original_code:
static inline void msg_init_header(struct msg_hdr *hdr, unsigned short client_id, unsigned char type, unsigned short len)
{
    hdr->client_id = htons(client_id);
    hdr->type = type;
    hdr->length = htons(len);
}

variable_types: struct msg_hdr { unsigned short client_id; unsigned char type; unsigned short length; } *

variable_types:
type
unsigned char

variable_types:
len
unsigned short


decompiled_code:
__int16 __fastcall msg_get_client_id(__int16 *a1)
{
return _bswap_16(*a1);
}

canonical_decompiled_code:
__int16 __fastcall func3(__int16 *a1)
{
return func1(*a1);
}

original_code:
static inline uint16_t msg_get_client_id(msg_hdr_t *h)
{
    return ntohs(h->client_id);
}

canonical_original_code:
static inline unsigned short msg_get_client_id(struct msg_hdr *h)
{
    return ntohs(h->client_id);
}

return_type: unsigned short

user_defined_types: struct msg_hdr { unsigned short client_id; unsigned char type; unsigned short length; }


decompiled_code:
__int16 __fastcall msg_get_length(__int64 a1)
{
return _bswap_16(*(_WORD *)(a1 + 3));
}

canonical_decompiled_code:
__int16 __fastcall func4(__int64 a1)
{
return func1(*(_WORD *)(a1 + 3));
}

original_code:
static inline uint16_t msg_get_length(msg_hdr_t *h)
{
    return ntohs(h->length);
}

canonical_original_code:
static inline unsigned short msg_get_length(struct msg_hdr *h)
{
    return ntohs(h->length);
}


decompiled_code:
__int64 __fastcall msg_send_msg(__int64 a1, __int16 a2, char a3, __int64 *a4, int a5)
{
unsigned int v5; // ebp
int v6; // eax
__int64 result; // rax
__int64 v8; // [rsp+1h] [rbp-42Bh] BYREF
__int64 v9[132]; // [rsp+9h] [rbp-423h] BYREF

if ( a5 > 1024 )
return 0xFFFFFFFFLL;
switch ( a3 )
{
case 1:
case 4:
case 7:
case 8:
a5 = 0;
goto LABEL_11;
case 2:
case 3:
case 5:
case 6:
if ( (unsigned __int64)a5 >= 8 )
{
v9[0] = *a4;
*(__int64 *)((char *)&v8 + a5) = *(__int64 *)((char *)a4 + a5 - 8);
qmemcpy(
(char *)v9 + 3,
(char *)a4 - ((char *)v9 - ((char *)v9 + 3)),
8 * ((unsigned __int64)((char *)v9 - ((char *)v9 + 3) + a5) >> 3));
}
else if ( (a5 & 4) != 0 )
{
LODWORD(v9[0]) = *(_DWORD *)a4;
*(_DWORD *)((char *)v9 + a5 - 4) = *(_DWORD *)((char *)a4 + a5 - 4);
}
else if ( a5 )
{
LOBYTE(v9[0]) = *(_BYTE *)a4;
if ( (a5 & 2) != 0 )
*(_WORD *)((char *)v9 + a5 - 2) = *(_WORD *)((char *)a4 + a5 - 2);
}
LABEL_11:
v5 = a5 + 5;
msg_init_header((__int64)&v8 + 3, a2, a3, a5);
v6 = sock_send(a1, (char *)&v8 + 3, v5);
if ( v6 < 0 )
result = 0xFFFFFFFFLL;
else
result = v6 == 0 ? 0xFFFFFFFE : 0;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int16 a2, char a3, __int64 *a4, int a5)
{
unsigned int v5; // ebp
int v6; // eax
__int64 result; // rax
__int64 v8; // [rsp+1h] [rbp-42Bh] BYREF
__int64 v9[132]; // [rsp+9h] [rbp-423h] BYREF

if ( a5 > 1024 )
return 0xFFFFFFFFLL;
switch ( a3 )
{
case 1:
case 4:
case 7:
case 8:
a5 = 0;
goto LABEL_11;
case 2:
case 3:
case 5:
case 6:
if ( (unsigned __int64)a5 >= 8 )
{
v9[0] = *a4;
*(__int64 *)((char *)&v8 + a5) = *(__int64 *)((char *)a4 + a5 - 8);
qmemcpy(
(char *)v9 + 3,
(char *)a4 - ((char *)v9 - ((char *)v9 + 3)),
8 * ((unsigned __int64)((char *)v9 - ((char *)v9 + 3) + a5) >> 3));
}
else if ( (a5 & 4) != 0 )
{
LODWORD(v9[0]) = *(_DWORD *)a4;
*(_DWORD *)((char *)v9 + a5 - 4) = *(_DWORD *)((char *)a4 + a5 - 4);
}
else if ( a5 )
{
LOBYTE(v9[0]) = *(_BYTE *)a4;
if ( (a5 & 2) != 0 )
*(_WORD *)((char *)v9 + a5 - 2) = *(_WORD *)((char *)a4 + a5 - 2);
}
LABEL_11:
v5 = a5 + 5;
func2((__int64)&v8 + 3, a2, a3, a5);
v6 = sock_send(a1, (char *)&v8 + 3, v5);
if ( v6 < 0 )
result = 0xFFFFFFFFLL;
else
result = v6 == 0 ? 0xFFFFFFFE : 0;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
int msg_send_msg(socket_t *to, uint16_t client_id, uint8_t type,
                 char *data, int data_len)
{
    char buf[1024 + sizeof(msg_hdr_t)];
    int len;
    if(data_len > 1024)
        return -1;
    switch(type)
    {
        case 0x02:
        case 0x03:
        case 0x05:
        case 0x06:
            memcpy(buf+sizeof(msg_hdr_t), data, data_len);
            break;
        case 0x01:
        case 0x04:
        case 0x07:
        case 0x08:
            data_len = 0;
            break;
        default:
            return -1;
    }
    len = data_len + sizeof(msg_hdr_t);
    msg_init_header((msg_hdr_t *)buf, client_id, type, data_len);
    len = sock_send(to, buf, len);
    if(len < 0)
        return -1;
    else if(len == 0)
        return -2;
    else
        return 0;
}

canonical_original_code:
int msg_send_msg(struct socket *to, unsigned short client_id, unsigned char type, char *data, int data_len)
{
    char buf[-1];
    int len;
    if(data_len > 1024)
        return -1;
    switch(type)
    {
        case 0x02:
        case 0x03:
        case 0x05:
        case 0x06:
            memcpy(buf+sizeof(msg_hdr_t), data, data_len);
            break;
        case 0x01:
        case 0x04:
        case 0x07:
        case 0x08:
            data_len = 0;
            break;
        default:
            return -1;
    }
    len = data_len + sizeof(msg_hdr_t);
    msg_init_header((struct msg_hdr *)buf, client_id, type, data_len);
    len = sock_send(to, buf, len);
    if(len < 0)
        return -1;
    else if(len == 0)
        return -2;
    else
        return 0;
}

variable_types:
data
char *

variable_types:
buf
char [-1]


decompiled_code:
__int64 __fastcall msg_send_hello(__int64 a1, const char *a2, const char *a3, __int16 a4)
{
int v6; // ebx
int v7; // ebx
char *v8; // rax
char *v9; // rbp
int v10; // ebx
__int64 result; // rax

v6 = strlen(a2);
v7 = strlen(a3) + v6;
v8 = (char *)malloc(v7 + 4);
if ( !v8 )
return 0xFFFFFFFFLL;
v9 = v8;
*(_WORD *)v8 = _bswap_16(a4);
snprintf(v9 + 2, v7 + 2, "%s %s", a2, a3);
v10 = msg_send_msg(a1, 0, 2, (__int64 *)v9, v7 + 3);
free(v9);
if ( v10 < 0 )
result = 0xFFFFFFFFLL;
else
result = v10 == 0 ? 0xFFFFFFFE : 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, const char *a3, __int16 a4)
{
int v6; // ebx
int v7; // ebx
char *v8; // rax
char *v9; // rbp
int v10; // ebx
__int64 result; // rax

v6 = strlen(a2);
v7 = strlen(a3) + v6;
v8 = (char *)malloc(v7 + 4);
if ( !v8 )
return 0xFFFFFFFFLL;
v9 = v8;
*(_WORD *)v8 = func1(a4);
snprintf(v9 + 2, v7 + 2, "%s %s", a2, a3);
v10 = func5(a1, 0, 2, (__int64 *)v9, v7 + 3);
free(v9);
if ( v10 < 0 )
result = 0xFFFFFFFFLL;
else
result = v10 == 0 ? 0xFFFFFFFE : 0;
return result;
}

original_code:
int msg_send_hello(socket_t *to, char *host, char *port, uint16_t req_id)
{
    char *data;
    int str_len;
    int len;
    str_len = strlen(host) + strlen(port) + 2;
    len = str_len + sizeof(req_id);
    data = malloc(len);
    if(!data)
        return -1;
    *((uint16_t *)data) = htons(req_id);
    snprintf(data + sizeof(req_id), str_len, "%s %s", host, port);
    len = msg_send_msg(to, 0, 0x02, data, len-1);
    free(data);
    if(len < 0)
        return -1;
    else if(len == 0)
        return -2;
    else
        return 0;
}

canonical_original_code:
int msg_send_hello(struct socket *to, char *host, char *port, unsigned short req_id)
{
    char *data;
    int str_len;
    int len;
    str_len = strlen(host) + strlen(port) + 2;
    len = str_len + sizeof(req_id);
    data = malloc(len);
    if(!data)
        return -1;
    *((unsigned short *)data) = htons(req_id);
    snprintf(data + sizeof(req_id), str_len, "%s %s", host, port);
    len = msg_send_msg(to, 0, 0x02, data, len-1);
    free(data);
    if(len < 0)
        return -1;
    else if(len == 0)
        return -2;
    else
        return 0;
}

variable_types:
host
char *

variable_types:
port
char *


decompiled_code:
__int64 __fastcall msg_recv_msg(__int64 a1, __int64 a2, void *a3, int a4, __int16 *a5, _BYTE *a6, unsigned __int16 *a7)
{
int v11; // eax
int v12; // ebp
unsigned __int16 v13; // ax
__int64 result; // rax
__int16 v15[2]; // [rsp+0h] [rbp-438h] BYREF
char src[1075]; // [rsp+5h] [rbp-433h] BYREF

v11 = sock_recv(a1, a2, v15, 1029LL);
if ( v11 < 0 )
return 0xFFFFFFFFLL;
v12 = v11;
if ( !v11 )
return 4294967294LL;
*a5 = msg_get_client_id(v15);
*a6 = msg_get_type((__int64)v15);
v13 = msg_get_length((__int64)v15);
if ( v12 - 5LL == v13 )
{
if ( v13 > a4 )
v13 = a4;
*a7 = v13;
memcpy(a3, src, v13);
result = 0LL;
}
else
{
*a7 = v13;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, void *a3, int a4, __int16 *a5, _BYTE *a6, unsigned __int16 *a7)
{
int v11; // eax
int v12; // ebp
unsigned __int16 v13; // ax
__int64 result; // rax
__int16 v15[2]; // [rsp+0h] [rbp-438h] BYREF
char src[1075]; // [rsp+5h] [rbp-433h] BYREF

v11 = sock_recv(a1, a2, v15, 1029LL);
if ( v11 < 0 )
return 0xFFFFFFFFLL;
v12 = v11;
if ( !v11 )
return 4294967294LL;
*a5 = func3(v15);
*a6 = func0((__int64)v15);
v13 = func4((__int64)v15);
if ( v12 - 5LL == v13 )
{
if ( v13 > a4 )
v13 = a4;
*a7 = v13;
memcpy(a3, src, v13);
result = 0LL;
}
else
{
*a7 = v13;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int msg_recv_msg(socket_t *sock, socket_t *from, char *data, int data_len,
                 uint16_t *client_id, uint8_t *type, uint16_t *length)
{
    char buf[1024 + sizeof(msg_hdr_t)];
    msg_hdr_t *hdr_ptr;
    char *msg_ptr;
    int ret;
    hdr_ptr = (msg_hdr_t *)buf;
    msg_ptr = buf + sizeof(msg_hdr_t);
    ret = sock_recv(sock, from, buf, sizeof(buf));
    if(ret < 0)
        return -1;
    else if(ret == 0)
        return -2;
    *client_id = msg_get_client_id(hdr_ptr);
    *type = msg_get_type(hdr_ptr);
    *length = msg_get_length(hdr_ptr);
    if(ret-sizeof(msg_hdr_t) != *length)
        return -1;
    *length = ((data_len) < (*length) ? (data_len) : (*length));
    memcpy(data, msg_ptr, *length);
    return 0;
}

canonical_original_code:
int msg_recv_msg(struct socket *sock, struct socket *from, char *data, int data_len, unsigned short *client_id, unsigned char *type, unsigned short *length)
{
    char buf[-1];
    struct msg_hdr *hdr_ptr;
    char *msg_ptr;
    int ret;
    hdr_ptr = (struct msg_hdr *)buf;
    msg_ptr = buf + sizeof(msg_hdr_t);
    ret = sock_recv(sock, from, buf, sizeof(buf));
    if(ret < 0)
        return -1;
    else if(ret == 0)
        return -2;
    *client_id = msg_get_client_id(hdr_ptr);
    *type = msg_get_type(hdr_ptr);
    *length = msg_get_length(hdr_ptr);
    if(ret-sizeof(msg_hdr_t) != *length)
        return -1;
    *length = ((data_len) < (*length) ? (data_len) : (*length));
    memcpy(data, msg_ptr, *length);
    return 0;
}

variable_types:
from
struct socket *

variable_types:
type
unsigned char *

variable_types:
length
unsigned short *

variable_types: ret int


repo: arturoc/shift

decompiled_code:
double __fastcall freenect_get_tilt_degs(__int64 a1)
{
return (double)*(char *)(a1 + 6) * 0.5;
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1)
{
return (double)*(char *)(a1 + 6) * 0.5;
}

original_code:
double freenect_get_tilt_degs(freenect_raw_tilt_state *state)
{
 return ((double)state->tilt_angle) / 2.;
}

canonical_original_code:
double freenect_get_tilt_degs(struct freenect_raw_tilt_state *state)
{
 return ((double)state->tilt_angle) / 2.;
}

variable_types: struct freenect_raw_tilt_state { short accelerometer_x; short accelerometer_y; short accelerometer_z; char tilt_angle; enum freenect_tilt_status_code { TILT_STATUS_STOPPED=0, TILT_STATUS_LIMIT=1, TILT_STATUS_MOVING=4 } tilt_status; } *

return_type: double

user_defined_types: struct freenect_raw_tilt_state { short accelerometer_x; short accelerometer_y; short accelerometer_z; char tilt_angle; enum freenect_tilt_status_code tilt_status; }


original_code:
void freenect_get_mks_accel(freenect_raw_tilt_state *state, double* x, double* y, double* z)
{
 *x = (double)state->accelerometer_x/819*9.80665;
 *y = (double)state->accelerometer_y/819*9.80665;
 *z = (double)state->accelerometer_z/819*9.80665;
}

canonical_original_code:
void freenect_get_mks_accel(struct freenect_raw_tilt_state *state, double *x, double *y, double *z)
{
 *x = (double)state->accelerometer_x/819*9.80665;
 *y = (double)state->accelerometer_y/819*9.80665;
 *z = (double)state->accelerometer_z/819*9.80665;
}

variable_types:
x
double *

variable_types:
y
double *

variable_types:
z
double *

user_defined_types: enum freenect_tilt_status_code { TILT_STATUS_STOPPED=0, TILT_STATUS_LIMIT=1, TILT_STATUS_MOVING=4 }


decompiled_code:
char *__fastcall new_str(char *src)
{
size_t v1; // r12
char *v2; // rax

v1 = strlen(src) + 1;
v2 = (char *)malloc(v1);
return strncpy(v2, src, v1);
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
size_t v1; // r12
char *v2; // rax

v1 = strlen(src) + 1;
v2 = (char *)malloc(v1);
return strncpy(v2, src, v1);
}

original_code:
char *new_str(const char *val) {
    size_t l = strlen(val);
    char *res = (char *)malloc(l + 1);
    strncpy(res, val, l + 1);
    return res;
}

canonical_original_code:
char *new_str(char *val) {
    unsigned long l = strlen(val);
    char *res = (char *)malloc(l + 1);
    strncpy(res, val, l + 1);
    return res;
}

variable_types:
val
char *

variable_types:
l
unsigned long

variable_types:
res
char *

return_type: char *


decompiled_code:
char *__fastcall str_cat(char *src, char *a2)
{
size_t v2; // rbp
size_t v3; // rax
char *v4; // rbp
size_t v5; // rax
size_t v6; // r13
size_t v7; // rax

v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
v5 = strlen(src);
strncpy(v4, src, v5 + 1);
v6 = strlen(a2);
v7 = strlen(src);
strncpy(&v4[v7], a2, v6 + 1);
return v4;
}

canonical_decompiled_code:
char *__fastcall func1(char *src, char *a2)
{
size_t v2; // rbp
size_t v3; // rax
char *v4; // rbp
size_t v5; // rax
size_t v6; // r13
size_t v7; // rax

v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
v5 = strlen(src);
strncpy(v4, src, v5 + 1);
v6 = strlen(a2);
v7 = strlen(src);
strncpy(&v4[v7], a2, v6 + 1);
return v4;
}

original_code:
char *str_cat(const char *a, const char *b) {
    char *res = (char *)malloc(strlen(a) + strlen(b) + 1);
    strncpy(res, a, strlen(a) + 1);
    strncpy(res + strlen(a), b, strlen(b) + 1);
    return res;
}

canonical_original_code:
char *str_cat(char *a, char *b) {
    char *res = (char *)malloc(strlen(a) + strlen(b) + 1);
    strncpy(res, a, strlen(a) + 1);
    strncpy(res + strlen(a), b, strlen(b) + 1);
    return res;
}

variable_types:
a
char *

variable_types:
b
char *


decompiled_code:
char *__fastcall str_split(char *s, char a2, int *a3)
{
size_t v4; // r14
int v5; // ebx
size_t v6; // rcx
unsigned __int64 v7; // rax
int v8; // ebx
int v9; // edx
size_t v10; // r14
void *v11; // r12

*a3 = 0;
v4 = 0LL;
v5 = 0;
if ( a2 == *s )
{
do
{
v5 = v4;
if ( strlen(s) <= v4 )
break;
v5 = v4 + 1;
*a3 = ++v4;
}
while ( s[v4] == a2 );
}
v6 = strlen(s);
v7 = v5 + 1LL;
v8 = 0;
do
{
v9 = v8++;
if ( v6 <= v7 )
break;
++v7;
}
while ( s[v7 - 1] != a2 );
v10 = v9 + 2;
v11 = malloc(v10);
memset(v11, 0, v10);
return strncpy((char *)v11, &s[*a3], v8);
}

canonical_decompiled_code:
char *__fastcall func2(char *s, char a2, int *a3)
{
size_t v4; // r14
int v5; // ebx
size_t v6; // rcx
unsigned __int64 v7; // rax
int v8; // ebx
int v9; // edx
size_t v10; // r14
void *v11; // r12

*a3 = 0;
v4 = 0LL;
v5 = 0;
if ( a2 == *s )
{
do
{
v5 = v4;
if ( strlen(s) <= v4 )
break;
v5 = v4 + 1;
*a3 = ++v4;
}
while ( s[v4] == a2 );
}
v6 = strlen(s);
v7 = v5 + 1LL;
v8 = 0;
do
{
v9 = v8++;
if ( v6 <= v7 )
break;
++v7;
}
while ( s[v7 - 1] != a2 );
v10 = v9 + 2;
v11 = malloc(v10);
memset(v11, 0, v10);
return strncpy((char *)v11, &s[*a3], v8);
}

original_code:
char *str_split(const char *a, const char b, int *start) {
    char *res;
    int size = 0;
    *start = 0;
    while(a[*start] == b && *start < strlen(a)) {
        ++(*start);
    }
    do {
        ++size;
        if(*start + size >= strlen(a)) {
            break;
        }
    } while(a[*start + size] != b);
    res = malloc(size + 1);
    memset(res, 0, size + 1);
    strncpy(res, a + *start, size);
    return res;
}

canonical_original_code:
char *str_split(char *a, char b, int *start) {
    char *res;
    int size = 0;
    *start = 0;
    while(a[*start] == b && *start < strlen(a)) {
        ++(*start);
    }
    do {
        ++size;
        if(*start + size >= strlen(a)) {
            break;
        }
    } while(a[*start + size] != b);
    res = malloc(size + 1);
    memset(res, 0, size + 1);
    strncpy(res, a + *start, size);
    return res;
}

variable_types: b char

variable_types:
start
int *

variable_types: size int


decompiled_code:
char *__fastcall str_split_rev(char *src, char a2, int *a3)
{
int v5; // eax
int v6; // edi
int v7; // eax
void *v8; // r12
int v9; // ebx

*a3 = strlen(src);
do
{
v5 = *a3 - 1;
*a3 = v5;
}
while ( src[v5] == a2 && v5 > 0 );
do
{
v6 = *a3;
v7 = *a3 - 1;
*a3 = v7;
}
while ( src[v7] != a2 && v7 >= 0 );
*a3 = v6;
v8 = malloc(v6 + 1);
v9 = *a3;
memset(v8, 0, v9 + 1);
return strncpy((char *)v8, src, v9);
}

canonical_decompiled_code:
char *__fastcall func3(char *src, char a2, int *a3)
{
int v5; // eax
int v6; // edi
int v7; // eax
void *v8; // r12
int v9; // ebx

*a3 = strlen(src);
do
{
v5 = *a3 - 1;
*a3 = v5;
}
while ( src[v5] == a2 && v5 > 0 );
do
{
v6 = *a3;
v7 = *a3 - 1;
*a3 = v7;
}
while ( src[v7] != a2 && v7 >= 0 );
*a3 = v6;
v8 = malloc(v6 + 1);
v9 = *a3;
memset(v8, 0, v9 + 1);
return strncpy((char *)v8, src, v9);
}

original_code:
char *str_split_rev(const char *a, const char b, int *pos) {
    char *res;
    *pos = strlen(a);
    while(a[--(*pos)] == b && *pos > 0);
    while(a[--(*pos)] != b && *pos >= 0);
    ++(*pos);
    res = (char *)malloc(*pos + 1);
    memset(res, 0, *pos + 1);
    strncpy(res, a, *pos);
    return res;
}

canonical_original_code:
char *str_split_rev(char *a, char b, int *pos) {
    char *res;
    *pos = strlen(a);
    while(a[--(*pos)] == b && *pos > 0);
    while(a[--(*pos)] != b && *pos >= 0);
    ++(*pos);
    res = (char *)malloc(*pos + 1);
    memset(res, 0, *pos + 1);
    strncpy(res, a, *pos);
    return res;
}

variable_types:
pos
int *


decompiled_code:
size_t __fastcall http_buffering(const void *a1, __int64 a2, __int64 a3, size_t *a4)
{
size_t v5; // r13
size_t v6; // r12
size_t v7; // r14
char *v8; // rbp
void *src; // [rsp+0h] [rbp-48h]

src = (void *)a4[1];
v5 = *a4;
v6 = a3 * a2;
v7 = *a4 + a3 * a2;
v8 = (char *)malloc(v7 + 1);
memset(v8, 0, v7 + 1);
memcpy(v8, src, v5);
memcpy(&v8[v5], a1, v6);
a4[1] = (size_t)v8;
*a4 = v7;
free(src);
return v6;
}

canonical_decompiled_code:
size_t __fastcall func1(const void *a1, __int64 a2, __int64 a3, size_t *a4)
{
size_t v5; // r13
size_t v6; // r12
size_t v7; // r14
char *v8; // rbp
void *src; // [rsp+0h] [rbp-48h]

src = (void *)a4[1];
v5 = *a4;
v6 = a3 * a2;
v7 = *a4 + a3 * a2;
v8 = (char *)malloc(v7 + 1);
memset(v8, 0, v7 + 1);
memcpy(v8, src, v5);
memcpy(&v8[v5], a1, v6);
a4[1] = (size_t)v8;
*a4 = v7;
free(src);
return v6;
}

original_code:
size_t http_buffering(char *buf, size_t size, size_t nmemb, void *userdata) {
    int i;
    char *tmp, *old_buf;
    struct http_buf_data *dst = (struct http_buf_data *)userdata;
    old_buf = dst -> buf;
    tmp = malloc(dst -> len + size * nmemb + 1);
    memset(tmp, 0, dst -> len + size * nmemb + 1);
    memcpy(tmp, dst -> buf, dst -> len);
    memcpy(tmp + (dst -> len), buf, size * nmemb);
    dst -> buf = tmp;
    dst -> len += size * nmemb;
    userdata = (void *)dst;
    free(old_buf);
    return size * nmemb;
}

canonical_original_code:
unsigned long http_buffering(char *buf, unsigned long size, unsigned long nmemb, void *userdata) {
    int i;
    char *tmp; char *old_buf;
    struct http_buf_data *dst = (struct http_buf_data *)userdata;
    old_buf = dst -> buf;
    tmp = malloc(dst -> len + size * nmemb + 1);
    memset(tmp, 0, dst -> len + size * nmemb + 1);
    memcpy(tmp, dst -> buf, dst -> len);
    memcpy(tmp + (dst -> len), buf, size * nmemb);
    dst -> buf = tmp;
    dst -> len += size * nmemb;
    userdata = (void *)dst;
    free(old_buf);
    return size * nmemb;
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
userdata
void *

variable_types: i int

variable_types:
tmp
char *

variable_types: struct http_buf_data { unsigned long len; char *buf; } *

return_type: unsigned long


decompiled_code:
__int64 __fastcall http_get_header_val(unsigned __int64 a1, __int64 a2, __int64 a3)
{
int v6; // er13
int v7; // er13
__int64 v8; // rdi
__int64 result; // rax
int v10; // er13
const char *v11; // rsi
char v12[256]; // [rsp+0h] [rbp-248h] BYREF
char v13[256]; // [rsp+100h] [rbp-148h] BYREF
char v14[27]; // [rsp+200h] [rbp-48h] BYREF
char s[45]; // [rsp+21Bh] [rbp-2Dh] BYREF

_isoc99_sscanf(a2, "HTTP/1.1 %s %s\r\n", s, v14);
v6 = strlen(s);
v7 = v6 + strlen(v14) + 12;
if ( !a3 )
return new_str(s);
v8 = v7;
result = 0LL;
if ( a1 >= v7 )
{
while ( 1 )
{
_isoc99_sscanf(a2 + v8, "%s", v12);
v10 = v7 + strlen(v12) + 1;
_isoc99_sscanf(a2 + v10, "%[^\r]", v13);
v11 = (const char *)str_cat(a3, ":");
if ( !strcmp(v12, v11) )
break;
v7 = v10 + strlen(v13) + 2;
v8 = v7;
if ( v7 > a1 )
return 0LL;
}
result = new_str(v13);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1, __int64 a2, __int64 a3)
{
int v6; // er13
int v7; // er13
__int64 v8; // rdi
__int64 result; // rax
int v10; // er13
const char *v11; // rsi
char v12[256]; // [rsp+0h] [rbp-248h] BYREF
char v13[256]; // [rsp+100h] [rbp-148h] BYREF
char v14[27]; // [rsp+200h] [rbp-48h] BYREF
char s[45]; // [rsp+21Bh] [rbp-2Dh] BYREF

_isoc99_sscanf(a2, "HTTP/1.1 %s %s\r\n", s, v14);
v6 = strlen(s);
v7 = v6 + strlen(v14) + 12;
if ( !a3 )
return new_str(s);
v8 = v7;
result = 0LL;
if ( a1 >= v7 )
{
while ( 1 )
{
_isoc99_sscanf(a2 + v8, "%s", v12);
v10 = v7 + strlen(v12) + 1;
_isoc99_sscanf(a2 + v10, "%[^\r]", v13);
v11 = (const char *)str_cat(a3, ":");
if ( !strcmp(v12, v11) )
break;
v7 = v10 + strlen(v13) + 2;
v8 = v7;
if ( v7 > a1 )
return 0LL;
}
result = new_str(v13);
}
return result;
}

original_code:
char *http_get_header_val(const struct http_buf_data raw, const char *key) {
    int current;
    char statusCode[5];
    char statusMsg[20];
    struct http_map *res, *tmp;
    sscanf(raw.buf, "HTTP/1.1 %s %s\r\n", statusCode, statusMsg);
    current = strlen(statusCode) + strlen(statusMsg) + 12;
    if(key == ((void *)0)) {
        return new_str(statusCode);
    }
    while(current <= raw.len) {
        char tmp_key[256];
        char tmp_val[256];
        sscanf(raw.buf + current, "%s", tmp_key);
        current += strlen(tmp_key) + 1;
        sscanf(raw.buf + current, "%[^\r]", tmp_val);
        if(strcmp(tmp_key, str_cat(key, ":")) == 0) {
            return new_str(tmp_val);
        }
        current += strlen(tmp_val) + 2;
    }
    return ((void *)0);
}

canonical_original_code:
char *http_get_header_val(struct http_buf_data raw, char *key) {
    int current;
    char statusCode[5];
    char statusMsg[20];
    struct http_map *res; struct http_map *tmp;
    sscanf(raw.buf, "HTTP/1.1 %s %s\r\n", statusCode, statusMsg);
    current = strlen(statusCode) + strlen(statusMsg) + 12;
    if(key == ((void *)0)) {
        return new_str(statusCode);
    }
    while(current <= raw.len) {
        char tmp_key[256];
        char tmp_val[256];
        sscanf(raw.buf + current, "%s", tmp_key);
        current += strlen(tmp_key) + 1;
        sscanf(raw.buf + current, "%[^\r]", tmp_val);
        if(strcmp(tmp_key, str_cat(key, ":")) == 0) {
            return new_str(tmp_val);
        }
        current += strlen(tmp_val) + 2;
    }
    return ((void *)0);
}

variable_types: struct http_buf_data { unsigned long len; char *buf; }

variable_types:
key
char *

variable_types: current int

variable_types:
statusCode
char [5]

variable_types:
statusMsg
char [20]

variable_types: struct http_map { char *key; char *val; } *


original_code:
char *build_url(const char *url, const struct http_map map[], size_t mapsize) {
    char *get_url;
    char *ret;
    int i;
    if(map != ((void *)0)) {
        get_url = new_str("?");
        for(i = 0; i < mapsize; ++i) {
            get_url = str_cat(get_url, map[i].key);
            get_url = str_cat(get_url, "=");
            get_url = str_cat(get_url, g_uri_escape_string(map[i].val, ((void *)0), ((json_bool)1)));
            if(i + 1 != mapsize) {
                get_url = str_cat(get_url, "&");
            }
        }
        ret = str_cat(url, get_url);
    } else {
        ret = new_str(url);
    }
    return ret;
}

canonical_original_code:
char *build_url(char *url, struct http_map map[], unsigned long mapsize) {
    char *get_url;
    char *ret;
    int i;
    if(map != ((void *)0)) {
        get_url = new_str("?");
        for(i = 0; i < mapsize; ++i) {
            get_url = str_cat(get_url, map[i].key);
            get_url = str_cat(get_url, "=");
            get_url = str_cat(get_url, g_uri_escape_string(map[i].val, ((void *)0), ((int)1)));
            if(i + 1 != mapsize) {
                get_url = str_cat(get_url, "&");
            }
        }
        ret = str_cat(url, get_url);
    } else {
        ret = new_str(url);
    }
    return ret;
}

variable_types:
url
char *

variable_types: struct http_map { char *key; char *val; } []

variable_types:
mapsize
unsigned long

variable_types:
ret
char *


decompiled_code:
time_t __fastcall o_establish_getcode(__int64 a1)
{
const char *v1; // rax
_BYTE v3[128]; // [rsp+0h] [rbp-C8h] BYREF
__int64 v4[9]; // [rsp+80h] [rbp-48h] BYREF

v4[0] = new_str("response_type");
v4[1] = *(_QWORD *)a1;
v4[2] = new_str("redirect_uri");
v4[3] = *(_QWORD *)(a1 + 24);
v4[4] = new_str("client_id");
v4[5] = *(_QWORD *)(a1 + 8);
v4[6] = new_str("scope");
v4[7] = new_str(**(_QWORD **)(a1 + 32));
v1 = (const char *)build_url("https://accounts.google.com/o/oauth2/auth", v4, 4LL);
fprintf(stdout, "Get and input the code from %s .\n", v1);
_isoc99_scanf("%127s", v3);
*(_QWORD *)(a1 + 40) = new_str(v3);
return time((time_t *)(a1 + 88));
}

canonical_decompiled_code:
time_t __fastcall func2(__int64 a1)
{
const char *v1; // rax
_BYTE v3[128]; // [rsp+0h] [rbp-C8h] BYREF
__int64 v4[9]; // [rsp+80h] [rbp-48h] BYREF

v4[0] = new_str("response_type");
v4[1] = *(_QWORD *)a1;
v4[2] = new_str("redirect_uri");
v4[3] = *(_QWORD *)(a1 + 24);
v4[4] = new_str("client_id");
v4[5] = *(_QWORD *)(a1 + 8);
v4[6] = new_str("scope");
v4[7] = new_str(**(_QWORD **)(a1 + 32));
v1 = (const char *)build_url("https://accounts.google.com/o/oauth2/auth", v4, 4LL);
fprintf(stdout, "Get and input the code from %s .\n", v1);
_isoc99_scanf("%127s", v3);
*(_QWORD *)(a1 + 40) = new_str(v3);
return time((time_t *)(a1 + 88));
}

original_code:
void o_establish_getcode(struct o_val_t *o_val) {
    struct http_map getmap[4];
    char code[128];
    int i;
    getmap[0].key = new_str("response_type");
    getmap[0].val = o_val -> response_type;
    getmap[1].key = new_str("redirect_uri");
    getmap[1].val = o_val -> redirect_uri;
    getmap[2].key = new_str("client_id");
    getmap[2].val = o_val -> client_id;
    getmap[3].key = new_str("scope");
    getmap[3].val = new_str(o_val -> scope[0]);
    for(i = 1; i < (sizeof(o_val -> scope)/sizeof(o_val -> scope[0])); ++i) {
        getmap[3].val = str_cat(getmap[3].val, " ");
        getmap[3].val = str_cat(getmap[3].val, o_val -> scope[i]);
    }
    fprintf(stdout, "Get and input the code from %s .\n", build_url("https://accounts.google.com/o/oauth2/auth", getmap, (sizeof(getmap)/sizeof(getmap[0]))));
    scanf("%127s", code);
    o_val -> code = new_str(code);
    time(&(o_val -> established_time));
}

variable_types: struct o_val_t { char *response_type; char *client_id; char *client_secret; char *redirect_uri; char **scope; char *code; char *grant_type; char *access_token; char *refresh_token; int expires_in; char *token_type; long established_time; } *

variable_types: struct http_map { char *key; char *val; } [4]

variable_types:
code
char [128]


main

repo: arunov/adix

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
int v5; // ebp
_QWORD *v6; // rax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
struct stat v13; // [rsp+0h] [rbp-A8h] BYREF

if ( argc == 2 )
{
if ( (unsigned int)stat((char *)argv[1], &v13) == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
fprintf(stderr, "%s: Unable to stat %s (%s)\n", *argv, argv[1], v8);
}
else
{
v4 = open(argv[1], 2);
v5 = v4;
if ( v4 == -1 )
{
v9 = __errno_location();
v10 = strerror(*v9);
fprintf(stderr, "%s: Unable to open %s (%s)\n", *argv, argv[1], v10);
}
else
{
v6 = mmap(0LL, v13.st_size, 3, 1, v4, 0LL);
if ( v6 == (_QWORD *)-1LL )
{
v11 = __errno_location();
v12 = strerror(*v11);
fprintf(stderr, "%s: Unable to map %s (%s)\n", *argv, argv[1], v12);
}
else
{
*(_DWORD *)v6 = 540422197;
v6[64] = 0x45444F4344414544LL;
munmap(v6, v13.st_size);
close(v5);
}
}
}
}
else
{
fprintf(stderr, "Usage: %s disk.img\n", *argv);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // eax
int v5; // ebp
_QWORD *v6; // rax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
int *v11; // rax
char *v12; // rax
struct stat v13; // [rsp+0h] [rbp-A8h] BYREF

if ( argc == 2 )
{
if ( (unsigned int)func9((char *)argv[1], &v13) == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
fprintf(stderr, "%s: Unable to stat %s (%s)\n", *argv, argv[1], v8);
}
else
{
v4 = open(argv[1], 2);
v5 = v4;
if ( v4 == -1 )
{
v9 = __errno_location();
v10 = strerror(*v9);
fprintf(stderr, "%s: Unable to open %s (%s)\n", *argv, argv[1], v10);
}
else
{
v6 = mmap(0LL, v13.st_size, 3, 1, v4, 0LL);
if ( v6 == (_QWORD *)-1LL )
{
v11 = __errno_location();
v12 = strerror(*v11);
fprintf(stderr, "%s: Unable to map %s (%s)\n", *argv, argv[1], v12);
}
else
{
*(_DWORD *)v6 = 540422197;
v6[64] = 0x45444F4344414544LL;
munmap(v6, v13.st_size);
close(v5);
}
}
}
}
else
{
fprintf(stderr, "Usage: %s disk.img\n", *argv);
}
return 0;
}

original_code:
int main(int argc, char* argv[]) {
 struct superblock* sb;
 int fd;
 struct sector { char contents[512]; }* disk;
 struct inode* ino;
 struct stat diskstat;
 if (argc != 2) {
  fprintf(stderr, "Usage: %s disk.img\n", argv[0]);
  return 0;
 }
 if (stat(argv[1], &diskstat) == -1) {
  fprintf(stderr, "%s: Unable to stat %s (%s)\n", argv[0], argv[1], strerror((*__errno_location ())));
  return 0;
 }
 fd = open(argv[1], 02);
 if (fd == -1) {
  fprintf(stderr, "%s: Unable to open %s (%s)\n", argv[0], argv[1], strerror((*__errno_location ())));
  return 0;
 }
 disk = mmap(((void *)0), diskstat.st_size, 0x1|0x2, 0x01, fd, 0);
 if (disk == ((void *) -1)) {
  fprintf(stderr, "%s: Unable to map %s (%s)\n", argv[0], argv[1], strerror((*__errno_location ())));
  return 0;
 }
 sb = (struct superblock*)&disk[0];
 sb->magic = 0x20363035;
 ino = (struct inode*)&disk[1];
 ino->refcount = 0x45444F4344414544;
 munmap(disk, diskstat.st_size);
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 struct superblock *sb;
 int fd;
 struct sector *disk;
 struct inode *ino;
 struct stat diskstat;
 if (argc != 2) {
  fprintf(stderr, "Usage: %s disk.img\n", argv[0]);
  return 0;
 }
 if (stat(argv[1], &diskstat) == -1) {
  fprintf(stderr, "%s: Unable to stat %s (%s)\n", argv[0], argv[1], strerror((*__errno_location ())));
  return 0;
 }
 fd = open(argv[1], 02);
 if (fd == -1) {
  fprintf(stderr, "%s: Unable to open %s (%s)\n", argv[0], argv[1], strerror((*__errno_location ())));
  return 0;
 }
 disk = mmap(((void *)0), diskstat.st_size, 0x1|0x2, 0x01, fd, 0);
 if (disk == ((void *) -1)) {
  fprintf(stderr, "%s: Unable to map %s (%s)\n", argv[0], argv[1], strerror((*__errno_location ())));
  return 0;
 }
 sb = (struct superblock *)&disk[0];
 sb->magic = 0x20363035;
 ino = (struct inode *)&disk[1];
 ino->refcount = 0x45444F4344414544;
 munmap(disk, diskstat.st_size);
 close(fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct superblock { unsigned int magic; } *

variable_types: fd int

variable_types:
disk
struct sector { char contents[512]; } *

variable_types: struct inode { unsigned long refcount; } *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( argc != 1 )
{
init_shell_env(envp);
process_exec_jobs(argc, argv, (char *const *)envp);
exit(0);
}
clrscr(argc, argv, envp);
init_shell();
run_shell();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( argc != 1 )
{
func2(envp);
func18(argc, argv, (char *const *)envp);
exit(0);
}
clrscr(argc, argv, envp);
func17();
func14();
}

user_defined_types: struct superblock { unsigned int magic; }

user_defined_types: struct inode { unsigned long refcount; }

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


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
int result; // eax
const char *v5; // rdi

if ( argc <= 1 )
{
v5 = (const char *)get_env("pwd", envp);
if ( v5 )
{
ls(v5);
result = 0;
}
else
{
printf("No environemnt variable %s\n", "pwd");
result = -1;
}
}
else
{
v3 = argv + 1;
do
ls(*v3++);
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
int result; // eax
const char *v5; // rdi

if ( argc <= 1 )
{
v5 = (const char *)get_env("pwd", envp);
if ( v5 )
{
func0(v5);
result = 0;
}
else
{
printf("No environemnt variable %s\n", "pwd");
result = -1;
}
}
else
{
v3 = argv + 1;
do
func0(*v3++);
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
result = 0;
}
return result;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func1();
return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // r13
__rlimit_resource_t v4; // er12
int result; // eax
int v6; // edx
struct rlimit v7; // [rsp+0h] [rbp-38h] BYREF

if ( argc == 1 )
goto LABEL_10;
if ( argc == 2 )
{
if ( !(unsigned int)str_equal(argv[1], "-a", envp) )
goto LABEL_4;
LABEL_10:
printallulimits();
return 0;
}
if ( (unsigned int)(argc - 2) > 1 )
{
LABEL_7:
printf("usage:\n%s [-a|[%s|%s|%s [<new-limit>]]]\n", *argv, res_flag[0], res_flag[1], res_flag[2]);
return 1;
}
LABEL_4:
v3 = res_flag;
v4 = RLIMIT_CPU;
while ( !(unsigned int)str_equal(argv[1], *v3, envp) )
{
++v4;
++v3;
if ( v4 == RLIMIT_STACK )
goto LABEL_7;
}
if ( argc == 3 )
{
v7.rlim_cur = atoi(argv[2]);
v6 = setrlimit(v4, &v7);
result = 0;
if ( v6 == -1 )
{
printf("setrlimit failed\n");
result = 0;
}
}
else
{
printulimit(v4);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // r13
__rlimit_resource_t v4; // er12
int result; // eax
int v6; // edx
struct rlimit v7; // [rsp+0h] [rbp-38h] BYREF

if ( argc == 1 )
goto LABEL_10;
if ( argc == 2 )
{
if ( !(unsigned int)str_equal(argv[1], "-a", envp) )
goto LABEL_4;
LABEL_10:
func1();
return 0;
}
if ( (unsigned int)(argc - 2) > 1 )
{
LABEL_7:
printf("usage:\n%s [-a|[%s|%s|%s [<new-limit>]]]\n", *argv, res_flag[0], res_flag[1], res_flag[2]);
return 1;
}
LABEL_4:
v3 = res_flag;
v4 = RLIMIT_CPU;
while ( !(unsigned int)str_equal(argv[1], *v3, envp) )
{
++v4;
++v3;
if ( v4 == RLIMIT_STACK )
goto LABEL_7;
}
if ( argc == 3 )
{
v7.rlim_cur = atoi(argv[2]);
v6 = setrlimit(v4, &v7);
result = 0;
if ( v6 == -1 )
{
printf("setrlimit failed\n");
result = 0;
}
}
else
{
func0(v4);
result = 0;
}
return result;
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
int v4; // eax
int v5; // ebx

if ( argc > 1 )
{
v3 = argv + 1;
while ( 1 )
{
v4 = open(*v3, (int)argv, envp);
v5 = v4;
if ( v4 < 0 )
break;
cat(v4);
close(v5);
if ( ++v3 == &argv[(unsigned int)(argc - 2) + 2] )
exit(0);
}
printf("cat: cannot open %s\n", *v3);
exit(0);
}
cat(0);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
int v4; // eax
int v5; // ebx

if ( argc > 1 )
{
v3 = argv + 1;
while ( 1 )
{
v4 = open(*v3, (int)argv, envp);
v5 = v4;
if ( v4 < 0 )
break;
func0(v4);
close(v5);
if ( ++v3 == &argv[(unsigned int)(argc - 2) + 2] )
exit(0);
}
printf("cat: cannot open %s\n", *v3);
exit(0);
}
func0(0);
exit(0);
}


repo: arut/htserve

decompiled_code:
__int64 __fastcall output_buf(int fd, void *buf, size_t n)
{
int v5; // eax

while ( 1 )
{
v5 = send(fd, buf, n, 0x4000);
if ( v5 == n )
break;
if ( v5 == -1 )
{
perror("send error");
return 1LL;
}
buf = (char *)buf + v5;
n -= v5;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, void *buf, size_t n)
{
int v5; // eax

while ( 1 )
{
v5 = send(fd, buf, n, 0x4000);
if ( v5 == n )
break;
if ( v5 == -1 )
{
perror("send error");
return 1LL;
}
buf = (char *)buf + v5;
n -= v5;
}
return 0LL;
}

original_code:
static int output_buf(int fd, const char *buf, size_t size)
{
 int ret;
 for(;;) {
  ret = send(fd, buf, size, MSG_NOSIGNAL);
  if (ret == size)
   return 0;
  if (ret == -1) {
   perror("send error");
   return 1;
  }
  buf += ret;
  size -= ret;
 }
}

canonical_original_code:
static int output_buf(int fd, char *buf, unsigned long size)
{
 int ret;
 for(;;) {
  ret = send(fd, buf, size, MSG_NOSIGNAL);
  if (ret == size)
   return 0;
  if (ret == -1) {
   perror("send error");
   return 1;
  }
  buf += ret;
  size -= ret;
 }
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types: ret int