decompiled_code:
__int64 __fastcall udp_send_buf(__int64 a1, const void *a2, int a3, __int64 a4)
{
int v5; // eax
__int16 v6; // dx
__int64 v7; // r13
__int64 (__fastcall *v8)(__int64, __int64); // rax
__int64 result; // rax
int v10; // edx
char v11[4]; // [rsp+0h] [rbp-34h] BYREF
int v12; // [rsp+4h] [rbp-30h]
__int16 v13; // [rsp+Ah] [rbp-2Ah]

if ( (unsigned int)(a3 - 1) > 0xFFF6 )
return 0xFFFFFFFFLL;
if ( a4 )
{
v5 = *(_DWORD *)(a4 + 4);
v6 = *(_WORD *)(a4 + 10);
v12 = v5;
v13 = v6;
LABEL_4:
if ( !v5 || !v13 )
return 0xFFFFFFFFLL;
goto LABEL_6;
}
if ( !*(_WORD *)(a1 + 11) )
{
v5 = v12;
goto LABEL_4;
}
v10 = *(_DWORD *)(a1 + 5);
v13 = *(_WORD *)(a1 + 11);
v12 = v10;
if ( !v10 )
return 0xFFFFFFFFLL;
LABEL_6:
if ( !*(_WORD *)(a1 + 9) && (int)sock_autobind(a1) < 0 )
return 0xFFFFFFFFLL;
v7 = alloc_pkb((unsigned int)(a3 + 42));
if ( (int)udp_init_pkb(a1, v7, a2, a3, (__int64)v11) < 0 )
{
free_pkb(v7);
return 0xFFFFFFFFLL;
}
v8 = *(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)(a1 + 21) + 16LL);
if ( v8 )
result = v8(a1, v7);
else
result = udp_send_pkb(a1, v7);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const void *a2, int a3, __int64 a4)
{
int v5; // eax
__int16 v6; // dx
__int64 v7; // r13
__int64 (__fastcall *v8)(__int64, __int64); // rax
__int64 result; // rax
int v10; // edx
char v11[4]; // [rsp+0h] [rbp-34h] BYREF
int v12; // [rsp+4h] [rbp-30h]
__int16 v13; // [rsp+Ah] [rbp-2Ah]

if ( (unsigned int)(a3 - 1) > 0xFFF6 )
return 0xFFFFFFFFLL;
if ( a4 )
{
v5 = *(_DWORD *)(a4 + 4);
v6 = *(_WORD *)(a4 + 10);
v12 = v5;
v13 = v6;
LABEL_4:
if ( !v5 || !v13 )
return 0xFFFFFFFFLL;
goto LABEL_6;
}
if ( !*(_WORD *)(a1 + 11) )
{
v5 = v12;
goto LABEL_4;
}
v10 = *(_DWORD *)(a1 + 5);
v13 = *(_WORD *)(a1 + 11);
v12 = v10;
if ( !v10 )
return 0xFFFFFFFFLL;
LABEL_6:
if ( !*(_WORD *)(a1 + 9) && (int)sock_autobind(a1) < 0 )
return 0xFFFFFFFFLL;
v7 = alloc_pkb((unsigned int)(a3 + 42));
if ( (int)func8(a1, v7, a2, a3, (__int64)v11) < 0 )
{
free_pkb(v7);
return 0xFFFFFFFFLL;
}
v8 = *(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)(a1 + 21) + 16LL);
if ( v8 )
result = v8(a1, v7);
else
result = func9(a1, v7);
return result;
}

original_code:
static int udp_send_buf(struct sock *sk, void *buf, int size,
    struct sock_addr *skaddr)
{
 struct sock_addr sk_addr;
 struct pkbuf *pkb;
 if (size <= 0 || size > (0xffff - sizeof(struct udp)))
  return -1;
 if (skaddr) {
  sk_addr.dst_addr = skaddr->dst_addr;
  sk_addr.dst_port = skaddr->dst_port;
 } else if (sk->sk_addr.dst_port) {
  sk_addr.dst_addr = sk->sk_addr.dst_addr;
  sk_addr.dst_port = sk->sk_addr.dst_port;
 }
 if (!sk_addr.dst_addr || !sk_addr.dst_port)
  return -1;
 if (!sk->sk_addr.src_port && sock_autobind(sk) < 0)
  return -1;
 pkb = alloc_pkb(sizeof(struct ether) + sizeof(struct ip) + sizeof(struct udp) + size);
 if (udp_init_pkb(sk, pkb, buf, size, &sk_addr) < 0) {
  free_pkb(pkb);
  return -1;
 }
 if (sk->ops->send_pkb)
  return sk->ops->send_pkb(sk, pkb);
 else
  return udp_send_pkb(sk, pkb);
}

variable_types: struct pkbuf { struct list_head { struct list_head *prev; } pk_list; unsigned short pk_pro; unsigned short pk_type; int pk_len; int pk_refcnt; struct netdev { int net_mtu; unsigned int net_ipaddr; unsigned int net_mask; unsigned char net_hwaddr[6]; unsigned char net_name[16]; struct netdev_ops { int (*xmit)(struct netdev *, struct pkbuf *); int (*init)(struct netdev *); void (*exit)(struct netdev *); } *net_ops; struct netstats { unsigned int rx_packets; unsigned int tx_packets; unsigned int rx_errors; unsigned int tx_errors; unsigned int rx_bytes; unsigned int tx_bytes; } net_stats; struct list_head net_list; } *pk_indev; struct rtentry { struct list_head rt_list; unsigned int rt_net; unsigned int rt_netmask; unsigned int rt_gw; unsigned int rt_flags; int rt_metric; struct netdev *rt_dev; } *pk_rtdst; struct sock { unsigned char protocol; struct sock_addr { unsigned int src_addr; unsigned int dst_addr; unsigned short src_port; unsigned short dst_port; } sk_addr; struct socket { unsigned int state; unsigned int family; unsigned int type; struct tapip_wait { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int notified; int dead; int sleep; } sleep; struct socket_ops { int (*socket)(struct socket *, int); int (*close)(struct socket *); int (*accept)(struct socket *, struct socket *, struct sock_addr *); int (*listen)(struct socket *, int); int (*bind)(struct socket *, struct sock_addr *); int (*connect)(struct socket *, struct sock_addr *); int (*read)(struct socket *, void *, int); int (*write)(struct socket *, void *, int); int (*send)(struct socket *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct socket *); } *ops; struct sock *sk; int refcnt; } *sock; struct sock_ops { void (*recv_notify)(struct sock *); void (*send_notify)(struct sock *); int (*send_pkb)(struct sock *, struct pkbuf *); int (*send_buf)(struct sock *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct sock *); int (*recv_buf)(struct sock *, char *, int); int (*hash)(struct sock *); void (*unhash)(struct sock *); int (*bind)(struct sock *, struct sock_addr *); int (*connect)(struct sock *, struct sock_addr *); int (*set_port)(struct sock *, unsigned short); int (*close)(struct sock *); int (*listen)(struct sock *, int); struct sock *(*accept)(struct sock *); } *ops; struct rtentry *sk_dst; struct list_head recv_queue; struct tapip_wait *recv_wait; unsigned int hash; struct hlist_node { struct hlist_node *next; struct hlist_node **pprev; } hash_list; int refcnt; } *pk_sk; unsigned char pk_data[]; } *

user_defined_types: struct socket { unsigned int state; unsigned int family; unsigned int type; struct tapip_wait sleep; struct socket_ops *ops; struct sock *sk; int refcnt; }


repo: chobits/tapip

decompiled_code:
__int64 udp_init()
{
__int64 *v0; // rax
__int64 result; // rax

v0 = udp_table;
do
{
*v0 = 0LL;
v0 += 2;
*((_DWORD *)v0 - 2) = 0;
}
while ( v0 != &qword_1520 );
qword_1520 = 0xA00000000LL;
pthread_mutex_init(&mutex, 0LL);
result = 0LL;
udp_id = 0;
return result;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 *v0; // rax
__int64 result; // rax

v0 = udp_table;
do
{
*v0 = 0LL;
v0 += 2;
*((_DWORD *)v0 - 2) = 0;
}
while ( v0 != &qword_1520 );
qword_1520 = 0xA00000000LL;
pthread_mutex_init(&mutex, 0LL);
result = 0LL;
udp_id = 0;
return result;
}

original_code:
void udp_init(void)
{
 struct hash_slot *slot;
 int i;
 for (slot = (&udp_table.slot[i = 0]); i < 128; i++, slot++) {
  hlist_head_init(&slot->head);
  slot->used = 0;
 }
 udp_table.best_slot = 0;
 udp_table.best_update = 10;
 pthread_mutex_init(&udp_table.mutex, ((void *)0));
 udp_id = 0;
}

canonical_original_code:
void udp_init()
{
 struct hash_slot *slot;
 int i;
 for (slot = (&udp_table.slot[i = 0]); i < 128; i++, slot++) {
  hlist_head_init(&slot->head);
  slot->used = 0;
 }
 udp_table.best_slot = 0;
 udp_table.best_update = 10;
 pthread_mutex_init(&udp_table.mutex, ((void *)0));
 udp_id = 0;
}

variable_types: struct hash_slot { struct hlist_head { struct hlist_node { struct hlist_node *next; struct hlist_node **pprev; } *first; } head; int used; } *

variable_types: i int

return_type: void

user_defined_types: struct hash_slot { struct hlist_head head; int used; }

user_defined_types: struct hlist_head { struct hlist_node *first; }


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

if ( !a1 || (result = 0LL, a1 == 17) )
{
result = xzalloc(85LL);
++alloc_socks;
++udp_id;
*(_QWORD *)(result + 21) = &udp_ops;
}
return result;
}

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

if ( !a1 || (result = 0LL, a1 == 17) )
{
result = xzalloc(85LL);
++alloc_socks;
++udp_id;
*(_QWORD *)(result + 21) = &udp_ops;
}
return result;
}

original_code:
struct sock *udp_alloc_sock(int protocol)
{
 struct udp_sock *udp_sk;
 if (protocol && protocol != 17)
  return ((void *)0);
 udp_sk = xzalloc(sizeof(*udp_sk));
 alloc_socks++;
 udp_sk->sk.ops = &udp_ops;
 udp_id++;
 return &udp_sk->sk;
}

variable_types: protocol int

variable_types: struct udp_sock { struct sock { unsigned char protocol; struct sock_addr { unsigned int src_addr; unsigned int dst_addr; unsigned short src_port; unsigned short dst_port; } sk_addr; struct socket { unsigned int state; unsigned int family; unsigned int type; struct tapip_wait { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int notified; int dead; int sleep; } sleep; struct socket_ops { int (*socket)(struct socket *, int); int (*close)(struct socket *); int (*accept)(struct socket *, struct socket *, struct sock_addr *); int (*listen)(struct socket *, int); int (*bind)(struct socket *, struct sock_addr *); int (*connect)(struct socket *, struct sock_addr *); int (*read)(struct socket *, void *, int); int (*write)(struct socket *, void *, int); int (*send)(struct socket *, void *, int, struct sock_addr *); struct pkbuf { struct list_head { struct list_head *prev; } pk_list; unsigned short pk_pro; unsigned short pk_type; int pk_len; int pk_refcnt; struct netdev { int net_mtu; unsigned int net_ipaddr; unsigned int net_mask; unsigned char net_hwaddr[6]; unsigned char net_name[16]; struct netdev_ops { int (*xmit)(struct netdev *, struct pkbuf *); int (*init)(struct netdev *); void (*exit)(struct netdev *); } *net_ops; struct netstats { unsigned int rx_packets; unsigned int tx_packets; unsigned int rx_errors; unsigned int tx_errors; unsigned int rx_bytes; unsigned int tx_bytes; } net_stats; struct list_head net_list; } *pk_indev; struct rtentry { struct list_head rt_list; unsigned int rt_net; unsigned int rt_netmask; unsigned int rt_gw; unsigned int rt_flags; int rt_metric; struct netdev *rt_dev; } *pk_rtdst; struct sock *pk_sk; unsigned char pk_data[]; } *(*recv)(struct socket *); } *ops; struct sock *sk; int refcnt; } *sock; struct sock_ops { void (*recv_notify)(struct sock *); void (*send_notify)(struct sock *); int (*send_pkb)(struct sock *, struct pkbuf *); int (*send_buf)(struct sock *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct sock *); int (*recv_buf)(struct sock *, char *, int); int (*hash)(struct sock *); void (*unhash)(struct sock *); int (*bind)(struct sock *, struct sock_addr *); int (*connect)(struct sock *, struct sock_addr *); int (*set_port)(struct sock *, unsigned short); int (*close)(struct sock *); int (*listen)(struct sock *, int); struct sock *(*accept)(struct sock *); } *ops; struct rtentry *sk_dst; struct list_head recv_queue; struct tapip_wait *recv_wait; unsigned int hash; struct hlist_node { struct hlist_node *next; struct hlist_node **pprev; } hash_list; int refcnt; } sk; } *

return_type: struct sock { unsigned char protocol; struct sock_addr { unsigned int src_addr; unsigned int dst_addr; unsigned short src_port; unsigned short dst_port; } sk_addr; struct socket { unsigned int state; unsigned int family; unsigned int type; struct tapip_wait { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int notified; int dead; int sleep; } sleep; struct socket_ops { int (*socket)(struct socket *, int); int (*close)(struct socket *); int (*accept)(struct socket *, struct socket *, struct sock_addr *); int (*listen)(struct socket *, int); int (*bind)(struct socket *, struct sock_addr *); int (*connect)(struct socket *, struct sock_addr *); int (*read)(struct socket *, void *, int); int (*write)(struct socket *, void *, int); int (*send)(struct socket *, void *, int, struct sock_addr *); struct pkbuf { struct list_head { struct list_head *prev; } pk_list; unsigned short pk_pro; unsigned short pk_type; int pk_len; int pk_refcnt; struct netdev { int net_mtu; unsigned int net_ipaddr; unsigned int net_mask; unsigned char net_hwaddr[6]; unsigned char net_name[16]; struct netdev_ops { int (*xmit)(struct netdev *, struct pkbuf *); int (*init)(struct netdev *); void (*exit)(struct netdev *); } *net_ops; struct netstats { unsigned int rx_packets; unsigned int tx_packets; unsigned int rx_errors; unsigned int tx_errors; unsigned int rx_bytes; unsigned int tx_bytes; } net_stats; struct list_head net_list; } *pk_indev; struct rtentry { struct list_head rt_list; unsigned int rt_net; unsigned int rt_netmask; unsigned int rt_gw; unsigned int rt_flags; int rt_metric; struct netdev *rt_dev; } *pk_rtdst; struct sock *pk_sk; unsigned char pk_data[]; } *(*recv)(struct socket *); } *ops; struct sock *sk; int refcnt; } *sock; struct sock_ops { void (*recv_notify)(struct sock *); void (*send_notify)(struct sock *); int (*send_pkb)(struct sock *, struct pkbuf *); int (*send_buf)(struct sock *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct sock *); int (*recv_buf)(struct sock *, char *, int); int (*hash)(struct sock *); void (*unhash)(struct sock *); int (*bind)(struct sock *, struct sock_addr *); int (*connect)(struct sock *, struct sock_addr *); int (*set_port)(struct sock *, unsigned short); int (*close)(struct sock *); int (*listen)(struct sock *, int); struct sock *(*accept)(struct sock *); } *ops; struct rtentry *sk_dst; struct list_head recv_queue; struct tapip_wait *recv_wait; unsigned int hash; struct hlist_node { struct hlist_node *next; struct hlist_node **pprev; } hash_list; int refcnt; } *

user_defined_types: struct sock { unsigned char protocol; struct sock_addr sk_addr; struct socket *sock; struct sock_ops *ops; struct rtentry *sk_dst; struct list_head recv_queue; struct tapip_wait *recv_wait; unsigned int hash; struct hlist_node hash_list; int refcnt; }

user_defined_types: struct tapip_wait { union pthread_mutex_t mutex; union pthread_cond_t cond; int notified; int dead; int sleep; }

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

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

user_defined_types: struct socket_ops { int (*socket)(struct socket *, int); int (*close)(struct socket *); int (*accept)(struct socket *, struct socket *, struct sock_addr *); int (*listen)(struct socket *, int); int (*bind)(struct socket *, struct sock_addr *); int (*connect)(struct socket *, struct sock_addr *); int (*read)(struct socket *, void *, int); int (*write)(struct socket *, void *, int); int (*send)(struct socket *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct socket *); }

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

user_defined_types: struct pkbuf { struct list_head pk_list; unsigned short pk_pro; unsigned short pk_type; int pk_len; int pk_refcnt; struct netdev *pk_indev; struct rtentry *pk_rtdst; struct sock *pk_sk; unsigned char pk_data[]; }

user_defined_types: struct netdev { int net_mtu; unsigned int net_ipaddr; unsigned int net_mask; unsigned char net_hwaddr[6]; unsigned char net_name[16]; struct netdev_ops *net_ops; struct netstats net_stats; struct list_head net_list; }


decompiled_code:
int raw_init()
{
__int64 v0; // rax

memset(raw_hash_table, 0, sizeof(raw_hash_table));
raw_id = 0;
v0 = syscall(186LL);
return fprintf(stderr, "[%d]%s raw ip init\n", v0, "raw_init");
}

canonical_decompiled_code:
int func6()
{
__int64 v0; // rax

memset(raw_hash_table, 0, sizeof(raw_hash_table));
raw_id = 0;
v0 = syscall(186LL);
return fprintf(stderr, "[%d]%s raw ip init\n", v0, "raw_init");
}

original_code:
void raw_init(void)
{
 int i;
 for (i = 0; i < 256; i++)
  hlist_head_init(&raw_hash_table[i]);
 raw_id = 0;
 fprintf(stderr, "[%d]%s " "raw ip init" "\n", (int)syscall(186), __FUNCTION__);
}

canonical_original_code:
void raw_init()
{
 int i;
 for (i = 0; i < 256; i++)
  hlist_head_init(&raw_hash_table[i]);
 raw_id = 0;
 fprintf(stderr, "[%d]%s " "raw ip init" "\n", (int)syscall(186), __FUNCTION__);
}


ethpro

decompiled_code:
const char *__fastcall ethpro(__int16 a1)
{
const char *result; // rax

result = "IP";
if ( a1 != 2048 )
{
result = (const char *)&unk_33A;
if ( a1 != 2054 )
{
result = "RARP";
if ( a1 != -32715 )
result = "unknown";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(__int16 a1)
{
const char *result; // rax

result = "IP";
if ( a1 != 2048 )
{
result = (const char *)&unk_33A;
if ( a1 != 2054 )
{
result = "RARP";
if ( a1 != -32715 )
result = "unknown";
}
}
return result;
}

original_code:
static inline char *ethpro(unsigned short proto)
{
 if (proto == 0x0800)
  return "IP";
 else if (proto == 0x0806)
  return "ARP";
 else if (proto == 0x8035)
  return "RARP";
 else
  return "unknown";
}

variable_types:
proto
unsigned short

return_type: char *


decompiled_code:
_BOOL8 __fastcall is_eth_broadcast(_BYTE *a1)
{
return (a1[5] & (unsigned __int8)(a1[4] & a1[3] & a1[2] & a1[1] & *a1)) == 0xFF;
}

original_code:
static inline int is_eth_broadcast(unsigned char *hwa)
{
 return (hwa[0] & hwa[1] & hwa[2] & hwa[3] & hwa[4] & hwa[5]) == 0xff;
}

variable_types:
hwa
unsigned char *

return_type: int


hwacmp

decompiled_code:
int __fastcall hwacmp(const void *a1, const void *a2)
{
return memcmp(a1, a2, 6uLL);
}

canonical_decompiled_code:
int __fastcall func2(const void *a1, const void *a2)
{
return memcmp(a1, a2, 6uLL);
}

original_code:
static inline int hwacmp(void *hwa1, void *hwa2)
{
 return memcmp(hwa1, hwa2, 6);
}


decompiled_code:
void __noreturn net_timer()
{
while ( 1 )
{
sleep(1u);
arp_timer(1LL);
ip_timer(1LL);
}
}

canonical_decompiled_code:
void __noreturn func6()
{
while ( 1 )
{
sleep(1u);
arp_timer(1LL);
ip_timer(1LL);
}
}

original_code:
void net_timer(void)
{
 while (1) {
  sleep(1);
  arp_timer(1);
  ip_timer(1);
 }
}

canonical_original_code:
void net_timer()
{
 while (1) {
  sleep(1);
  arp_timer(1);
  ip_timer(1);
 }
}


ethpro

decompiled_code:
const char *__fastcall ethpro(__int16 a1)
{
const char *result; // rax

result = "IP";
if ( a1 != 2048 )
{
result = (const char *)&unk_330;
if ( a1 != 2054 )
{
result = "RARP";
if ( a1 != -32715 )
result = "unknown";
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(__int16 a1)
{
const char *result; // rax

result = "IP";
if ( a1 != 2048 )
{
result = (const char *)&unk_330;
if ( a1 != 2054 )
{
result = "RARP";
if ( a1 != -32715 )
result = "unknown";
}
}
return result;
}

canonical_original_code:
static inline char *ethpro(unsigned short proto)
{
 if (proto == 0x0800)
  return "IP";
 else if (proto == 0x0806)
  return "ARP";
 else if (proto == 0x8035)
  return "RARP";
 else
  return "unknown";
}


hwacpy

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

*(_DWORD *)a1 = *(_DWORD *)a2;
result = *(unsigned __int16 *)(a2 + 4);
*(_WORD *)(a1 + 4) = result;
return result;
}

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

*(_DWORD *)a1 = *(_DWORD *)a2;
result = *(unsigned __int16 *)(a2 + 4);
*(_WORD *)(a1 + 4) = result;
return result;
}

original_code:
static inline void hwacpy(void *dst, void *src)
{
 memcpy(dst, src, 6);
}

variable_types:
dst
void *

variable_types:
src
void *


decompiled_code:
// attributes: thunk
__int64 netdev_interrupt()
{
return veth_poll();
}

canonical_decompiled_code:
__int64 func4()
{
return veth_poll();
}

original_code:
void netdev_interrupt(void)
{
 veth_poll();
}

canonical_original_code:
void netdev_interrupt()
{
 veth_poll();
}


decompiled_code:
__int64 netdev_init()
{
*(&net_devices + 1) = (__int64)&net_devices;
net_devices = (__int64)&net_devices;
loop_init();
return veth_init();
}

canonical_decompiled_code:
__int64 func5()
{
*(&net_devices + 1) = (__int64)&net_devices;
net_devices = (__int64)&net_devices;
loop_init();
return veth_init();
}

original_code:
void netdev_init(void)
{
 list_init(&net_devices);
 loop_init();
 veth_init();
}

canonical_original_code:
void netdev_init()
{
 list_init(&net_devices);
 loop_init();
 veth_init();
}


decompiled_code:
__int64 netdev_exit()
{
veth_exit();
return loop_exit();
}

canonical_decompiled_code:
__int64 func6()
{
veth_exit();
return loop_exit();
}

original_code:
void netdev_exit(void)
{
 veth_exit();
 loop_exit();
}

canonical_original_code:
void netdev_exit()
{
 veth_exit();
 loop_exit();
}


decompiled_code:
void __noreturn tcp_timer()
{
int v0; // ebx

v0 = 1;
timewait = 0LL;
usleep(0x30D40u);
while ( 1 )
{
do
{
++v0;
usleep(0x30D40u);
}
while ( (unsigned int)(-858993459 * v0) > 0x33333333 );
tcp_timewait_timer(1000000);
}
}

original_code:
void tcp_timer(void)
{
 unsigned int i = 0;
 timewait.next = ((void *)0);
 while (1) {
  usleep(200000);
  i++;
  if ((i % (1000000 / 200000)) == 0)
   tcp_timewait_timer(1000000);
 }
}

canonical_original_code:
void tcp_timer()
{
 unsigned int i = 0;
 timewait.next = ((void *)0);
 while (1) {
  usleep(200000);
  i++;
  if ((i % (1000000 / 200000)) == 0)
   tcp_timewait_timer(1000000);
 }
}

variable_types:
i
unsigned int


equsubnet

decompiled_code:
_BOOL8 __fastcall equsubnet(int a1, int a2, int a3)
{
return (a1 & (a3 ^ a2)) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1, int a2, int a3)
{
return (a1 & (a3 ^ a2)) == 0;
}

original_code:
static inline int equsubnet(unsigned int mask, unsigned int ip1, unsigned int ip2)
{
 return ((mask & ip1) == (mask & ip2));
}

variable_types:
mask
unsigned int


original_code:
void ip_forward(struct pkbuf *pkb)
{
 struct ip *iphdr = ((struct ip *)((pkb)->pk_data + sizeof(struct ether)));
 struct rtentry *rt = pkb->pk_rtdst;
 struct netdev *indev = pkb->pk_indev;
 unsigned int dst;
 do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""%d.%d.%d.%d" " -> " "%d.%d.%d.%d" "(%d/%d bytes) forwarding" "\n", (int)syscall(186), __FUNCTION__, (iphdr->ip_src) & 0xff, ((iphdr->ip_src) >> 8) & 0xff, ((iphdr->ip_src) >> 16) & 0xff, ((iphdr->ip_src) >> 24) & 0xff, (iphdr->ip_dst) & 0xff, ((iphdr->ip_dst) >> 8) & 0xff, ((iphdr->ip_dst) >> 16) & 0xff, ((iphdr->ip_dst) >> 24) & 0xff, ((iphdr)->ip_hlen << 2), _htons(iphdr->ip_len));} while (0);
 if (iphdr->ip_ttl <= 1) {
  icmp_send(11, 0, 0, pkb);
  goto drop_pkb;
 }
 iphdr->ip_ttl--;
 ip_set_checksum(iphdr);
 if ((rt->rt_flags & 0x00000002) || rt->rt_metric > 0)
  dst = rt->rt_gw;
 else
  dst = iphdr->ip_dst;
 do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""forward to next-hop ""%d.%d.%d.%d" "\n", (int)syscall(186), __FUNCTION__, (dst) & 0xff, ((dst) >> 8) & 0xff, ((dst) >> 16) & 0xff, ((dst) >> 24) & 0xff);} while (0);
 if (indev == rt->rt_dev) {
  struct rtentry *srt = rt_lookup(iphdr->ip_src);
  if (srt && srt->rt_metric == 0 &&
   equsubnet(srt->rt_netmask, iphdr->ip_src, dst)) {
   if (srt->rt_dev != indev) {
    do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""Two NIC are connected to the same LAN" "\n", (int)syscall(186), __FUNCTION__);} while (0);
   }
   icmp_send(5, 1, dst, pkb);
  }
 }
 if (_htons(iphdr->ip_len) > rt->rt_dev->net_mtu) {
  if (iphdr->ip_fragoff & _htons(0x4000)) {
   icmp_send(3, 4, 0, pkb);
   goto drop_pkb;
  }
  ip_send_frag(rt->rt_dev, pkb);
 } else {
  ip_send_dev(rt->rt_dev, pkb);
 }
 return;
drop_pkb:
 free_pkb(pkb);
}

variable_types: struct ip { unsigned char ip_hlen; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_fragoff; unsigned char ip_ttl; unsigned char ip_pro; unsigned short ip_cksum; unsigned int ip_src; unsigned int ip_dst; unsigned char ip_data[]; } *

variable_types: struct rtentry { struct list_head { struct list_head *prev; } rt_list; unsigned int rt_net; unsigned int rt_netmask; unsigned int rt_gw; unsigned int rt_flags; int rt_metric; struct netdev { int net_mtu; unsigned int net_ipaddr; unsigned int net_mask; unsigned char net_hwaddr[6]; unsigned char net_name[16]; struct netdev_ops { int (*xmit)(struct netdev *, struct pkbuf { struct list_head pk_list; unsigned short pk_pro; unsigned short pk_type; int pk_len; int pk_refcnt; struct netdev *pk_indev; struct rtentry *pk_rtdst; struct sock { unsigned char protocol; struct sock_addr { unsigned int src_addr; unsigned int dst_addr; unsigned short src_port; unsigned short dst_port; } sk_addr; struct socket { unsigned int state; unsigned int family; unsigned int type; struct tapip_wait { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int notified; int dead; int sleep; } sleep; struct socket_ops { int (*socket)(struct socket *, int); int (*close)(struct socket *); int (*accept)(struct socket *, struct socket *, struct sock_addr *); int (*listen)(struct socket *, int); int (*bind)(struct socket *, struct sock_addr *); int (*connect)(struct socket *, struct sock_addr *); int (*read)(struct socket *, void *, int); int (*write)(struct socket *, void *, int); int (*send)(struct socket *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct socket *); } *ops; struct sock *sk; int refcnt; } *sock; struct sock_ops { void (*recv_notify)(struct sock *); void (*send_notify)(struct sock *); int (*send_pkb)(struct sock *, struct pkbuf *); int (*send_buf)(struct sock *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct sock *); int (*recv_buf)(struct sock *, char *, int); int (*hash)(struct sock *); void (*unhash)(struct sock *); int (*bind)(struct sock *, struct sock_addr *); int (*connect)(struct sock *, struct sock_addr *); int (*set_port)(struct sock *, unsigned short); int (*close)(struct sock *); int (*listen)(struct sock *, int); struct sock *(*accept)(struct sock *); } *ops; struct rtentry *sk_dst; struct list_head recv_queue; struct tapip_wait *recv_wait; unsigned int hash; struct hlist_node { struct hlist_node *next; struct hlist_node **pprev; } hash_list; int refcnt; } *pk_sk; unsigned char pk_data[]; } *); int (*init)(struct netdev *); void (*exit)(struct netdev *); } *net_ops; struct netstats { unsigned int rx_packets; unsigned int tx_packets; unsigned int rx_errors; unsigned int tx_errors; unsigned int rx_bytes; unsigned int tx_bytes; } net_stats; struct list_head net_list; } *rt_dev; } *

variable_types: struct netdev { int net_mtu; unsigned int net_ipaddr; unsigned int net_mask; unsigned char net_hwaddr[6]; unsigned char net_name[16]; struct netdev_ops { int (*xmit)(struct netdev *, struct pkbuf { struct list_head { struct list_head *prev; } pk_list; unsigned short pk_pro; unsigned short pk_type; int pk_len; int pk_refcnt; struct netdev *pk_indev; struct rtentry { struct list_head rt_list; unsigned int rt_net; unsigned int rt_netmask; unsigned int rt_gw; unsigned int rt_flags; int rt_metric; struct netdev *rt_dev; } *pk_rtdst; struct sock { unsigned char protocol; struct sock_addr { unsigned int src_addr; unsigned int dst_addr; unsigned short src_port; unsigned short dst_port; } sk_addr; struct socket { unsigned int state; unsigned int family; unsigned int type; struct tapip_wait { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int notified; int dead; int sleep; } sleep; struct socket_ops { int (*socket)(struct socket *, int); int (*close)(struct socket *); int (*accept)(struct socket *, struct socket *, struct sock_addr *); int (*listen)(struct socket *, int); int (*bind)(struct socket *, struct sock_addr *); int (*connect)(struct socket *, struct sock_addr *); int (*read)(struct socket *, void *, int); int (*write)(struct socket *, void *, int); int (*send)(struct socket *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct socket *); } *ops; struct sock *sk; int refcnt; } *sock; struct sock_ops { void (*recv_notify)(struct sock *); void (*send_notify)(struct sock *); int (*send_pkb)(struct sock *, struct pkbuf *); int (*send_buf)(struct sock *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct sock *); int (*recv_buf)(struct sock *, char *, int); int (*hash)(struct sock *); void (*unhash)(struct sock *); int (*bind)(struct sock *, struct sock_addr *); int (*connect)(struct sock *, struct sock_addr *); int (*set_port)(struct sock *, unsigned short); int (*close)(struct sock *); int (*listen)(struct sock *, int); struct sock *(*accept)(struct sock *); } *ops; struct rtentry *sk_dst; struct list_head recv_queue; struct tapip_wait *recv_wait; unsigned int hash; struct hlist_node { struct hlist_node *next; struct hlist_node **pprev; } hash_list; int refcnt; } *pk_sk; unsigned char pk_data[]; } *); int (*init)(struct netdev *); void (*exit)(struct netdev *); } *net_ops; struct netstats { unsigned int rx_packets; unsigned int tx_packets; unsigned int rx_errors; unsigned int tx_errors; unsigned int rx_bytes; unsigned int tx_bytes; } net_stats; struct list_head net_list; } *

variable_types:
dst
unsigned int

user_defined_types: struct netdev_ops { int (*xmit)(struct netdev *, struct pkbuf *); int (*init)(struct netdev *); void (*exit)(struct netdev *); }


decompiled_code:
int __fastcall ip_recv_local(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int16 v3; // ax
__int64 v4; // rax
char v5; // al
__int64 v6; // rax
__int64 v7; // rax

v1 = a1;
v2 = a1 + 66;
v3 = *(_WORD *)(a1 + 72);
if ( (v3 & 0x3FFF) != 0 )
{
if ( (v3 & 0x4000) != 0 )
{
if ( (net_debug & 8) != 0 )
{
v6 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m error fragment\n", v6, "ip_recv_local");
}
LODWORD(v4) = free_pkb(a1);
return v4;
}
v4 = ip_reass();
v1 = v4;
v2 = v4 + 66;
if ( !v4 )
return v4;
}
raw_in(v1);
v5 = *(_BYTE *)(v2 + 9);
switch ( v5 )
{
case 6:
LODWORD(v4) = tcp_in(v1);
break;
case 17:
LODWORD(v4) = udp_in(v1);
break;
case 1:
LODWORD(v4) = icmp_in(v1);
break;
default:
LODWORD(v4) = free_pkb(v1);
if ( (net_debug & 8) != 0 )
{
v7 = syscall(186LL);
LODWORD(v4) = fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m unknown protocol\n", v7, "ip_recv_local");
}
break;
}
return v4;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int16 v3; // ax
__int64 v4; // rax
char v5; // al
__int64 v6; // rax
__int64 v7; // rax

v1 = a1;
v2 = a1 + 66;
v3 = *(_WORD *)(a1 + 72);
if ( (v3 & 0x3FFF) != 0 )
{
if ( (v3 & 0x4000) != 0 )
{
if ( (net_debug & 8) != 0 )
{
v6 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m error fragment\n", v6, "ip_recv_local");
}
LODWORD(v4) = free_pkb(a1);
return v4;
}
v4 = ip_reass();
v1 = v4;
v2 = v4 + 66;
if ( !v4 )
return v4;
}
raw_in(v1);
v5 = *(_BYTE *)(v2 + 9);
switch ( v5 )
{
case 6:
LODWORD(v4) = tcp_in(v1);
break;
case 17:
LODWORD(v4) = udp_in(v1);
break;
case 1:
LODWORD(v4) = icmp_in(v1);
break;
default:
LODWORD(v4) = free_pkb(v1);
if ( (net_debug & 8) != 0 )
{
v7 = syscall(186LL);
LODWORD(v4) = fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m unknown protocol\n", v7, "ip_recv_local");
}
break;
}
return v4;
}

original_code:
void ip_recv_local(struct pkbuf *pkb)
{
 struct ip *iphdr = ((struct ip *)((pkb)->pk_data + sizeof(struct ether)));
 if (iphdr->ip_fragoff & (0x1fff | 0x2000)) {
  if (iphdr->ip_fragoff & 0x4000) {
   do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""error fragment" "\n", (int)syscall(186), __FUNCTION__);} while (0);
   free_pkb(pkb);
   return;
  }
  pkb = ip_reass(pkb);
  if (!pkb)
   return;
  iphdr = ((struct ip *)((pkb)->pk_data + sizeof(struct ether)));
 }
 raw_in(pkb);
 switch (iphdr->ip_pro) {
 case 1:
  icmp_in(pkb);
  break;
 case 6:
  tcp_in(pkb);
  break;
 case 17:
  udp_in(pkb);
  break;
 default:
  free_pkb(pkb);
  do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""unknown protocol" "\n", (int)syscall(186), __FUNCTION__);} while (0);
  break;
 }
}

user_defined_types: struct ether { unsigned char eth_dst[6]; unsigned char eth_src[6]; unsigned short eth_pro; unsigned char eth_data[]; }

user_defined_types: struct ip { unsigned char ip_hlen; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_fragoff; unsigned char ip_ttl; unsigned char ip_pro; unsigned short ip_cksum; unsigned int ip_src; unsigned int ip_dst; unsigned char ip_data[]; }

user_defined_types: struct list_head { struct list_head *prev; }

user_defined_types: struct rtentry { struct list_head rt_list; unsigned int rt_net; unsigned int rt_netmask; unsigned int rt_gw; unsigned int rt_flags; int rt_metric; struct netdev *rt_dev; }

user_defined_types: struct netstats { unsigned int rx_packets; unsigned int tx_packets; unsigned int rx_errors; unsigned int tx_errors; unsigned int rx_bytes; unsigned int tx_bytes; }

user_defined_types: struct sock_addr { unsigned int src_addr; unsigned int dst_addr; unsigned short src_port; unsigned short dst_port; }

user_defined_types: struct hlist_node { struct hlist_node *next; struct hlist_node **pprev; }

user_defined_types: struct sock_ops { void (*recv_notify)(struct sock *); void (*send_notify)(struct sock *); int (*send_pkb)(struct sock *, struct pkbuf *); int (*send_buf)(struct sock *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct sock *); int (*recv_buf)(struct sock *, char *, int); int (*hash)(struct sock *); void (*unhash)(struct sock *); int (*bind)(struct sock *, struct sock_addr *); int (*connect)(struct sock *, struct sock_addr *); int (*set_port)(struct sock *, unsigned short); int (*close)(struct sock *); int (*listen)(struct sock *, int); struct sock *(*accept)(struct sock *); }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
int __fastcall ip_recv_route(__int64 a1)
{
int result; // eax

result = rt_input();
if ( result >= 0 )
{
if ( (*(_BYTE *)(*(_QWORD *)(a1 + 36) + 28LL) & 1) != 0 )
{
result = ip_recv_local(a1);
}
else
{
ip_ntoh((_WORD *)(a1 + 66));
result = ip_forward(a1);
}
}
return result;
}

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

result = rt_input();
if ( result >= 0 )
{
if ( (*(_BYTE *)(*(_QWORD *)(a1 + 36) + 28LL) & 1) != 0 )
{
result = func1(a1);
}
else
{
func0((_WORD *)(a1 + 66));
result = ip_forward(a1);
}
}
return result;
}

original_code:
void ip_recv_route(struct pkbuf *pkb)
{
 if (rt_input(pkb) < 0)
  return;
 if (pkb->pk_rtdst->rt_flags & 0x00000001) {
  ip_recv_local(pkb);
 } else {
  ip_ntoh(((struct ip *)((pkb)->pk_data + sizeof(struct ether))));
  ip_forward(pkb);
 }
}

user_defined_types: struct sock { unsigned char protocol; struct sock_addr sk_addr; struct socket *sock; struct sock_ops *ops; struct rtentry *sk_dst; struct list_head recv_queue; struct tapip_wait *recv_wait; unsigned int hash; struct hlist_node hash_list; int refcnt; }

user_defined_types: struct socket { unsigned int state; unsigned int family; unsigned int type; struct tapip_wait sleep; struct socket_ops *ops; struct sock *sk; int refcnt; }

user_defined_types: struct tapip_wait { union pthread_mutex_t mutex; union pthread_cond_t cond; int notified; int dead; int sleep; }

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


decompiled_code:
int __fastcall ip_in(__int64 a1, __int64 a2)
{
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rdx
unsigned __int64 v10; // rcx
__int64 v11; // rax
unsigned int v12; // er13
unsigned int v13; // er12
__int64 v14; // r14
__int64 v15; // rdx

if ( *(_WORD *)(a2 + 18) == 2 )
{
if ( (net_debug & 8) != 0 )
{
v6 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m ip(l2) packet is not for us\n", v6, "ip_in");
}
return free_pkb(a2);
}
if ( *(_DWORD *)(a2 + 20) <= 0x21u )
{
if ( (net_debug & 8) != 0 )
{
v5 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m ip packet is too small\n", v5, "ip_in");
}
return free_pkb(a2);
}
if ( (*(_BYTE *)(a2 + 66) & 0xF0) != 64 )
{
if ( (net_debug & 8) != 0 )
{
v8 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m ip packet is not version 4\n", v8, "ip_in");
}
return free_pkb(a2);
}
v3 = 4 * (*(_BYTE *)(a2 + 66) & 0xFu);
if ( (int)v3 <= 19 )
{
if ( (net_debug & 8) != 0 )
{
v4 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m ip header is too small\n", v4, "ip_in");
}
return free_pkb(a2);
}
if ( (unsigned __int16)ip_chksum(a2 + 66, (unsigned int)v3) )
{
if ( (net_debug & 8) != 0 )
{
v7 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m ip checksum is error\n", v7, "ip_in");
}
return free_pkb(a2);
}
ip_ntoh((_WORD *)(a2 + 66));
v9 = *(unsigned __int16 *)(a2 + 68);
if ( (int)v9 < (int)v3 || (v10 = *(int *)(a2 + 20), v10 < v9 + 14) )
{
if ( (net_debug & 8) != 0 )
{
v11 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m ip size is unknown\n", v11, "ip_in");
}
return free_pkb(a2);
}
if ( v10 > v9 + 14 )
pkb_trim(a2, (unsigned int)(v9 + 14));
if ( (net_debug & 8) != 0 )
{
v12 = *(_DWORD *)(a2 + 78);
v13 = *(_DWORD *)(a2 + 82);
v14 = *(unsigned __int16 *)(a2 + 68);
v15 = syscall(186LL);
fprintf(
stderr,
"[%d]%s \x1B[01;34mip\x1B[0m %d.%d.%d.%d -> %d.%d.%d.%d(%d/%d bytes)\n",
v15,
"ip_in",
(unsigned __int8)v12,
BYTE1(v12),
BYTE2(v12),
HIBYTE(v12),
(unsigned __int8)v13,
BYTE1(v13),
BYTE2(v13),
HIBYTE(v13),
v3,
v14);
}
return ip_recv_route(a2);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rdx
unsigned __int64 v10; // rcx
__int64 v11; // rax
unsigned int v12; // er13
unsigned int v13; // er12
__int64 v14; // r14
__int64 v15; // rdx

if ( *(_WORD *)(a2 + 18) == 2 )
{
if ( (net_debug & 8) != 0 )
{
v6 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m ip(l2) packet is not for us\n", v6, "ip_in");
}
return free_pkb(a2);
}
if ( *(_DWORD *)(a2 + 20) <= 0x21u )
{
if ( (net_debug & 8) != 0 )
{
v5 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m ip packet is too small\n", v5, "ip_in");
}
return free_pkb(a2);
}
if ( (*(_BYTE *)(a2 + 66) & 0xF0) != 64 )
{
if ( (net_debug & 8) != 0 )
{
v8 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m ip packet is not version 4\n", v8, "ip_in");
}
return free_pkb(a2);
}
v3 = 4 * (*(_BYTE *)(a2 + 66) & 0xFu);
if ( (int)v3 <= 19 )
{
if ( (net_debug & 8) != 0 )
{
v4 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m ip header is too small\n", v4, "ip_in");
}
return free_pkb(a2);
}
if ( (unsigned __int16)ip_chksum(a2 + 66, (unsigned int)v3) )
{
if ( (net_debug & 8) != 0 )
{
v7 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m ip checksum is error\n", v7, "ip_in");
}
return free_pkb(a2);
}
func0((_WORD *)(a2 + 66));
v9 = *(unsigned __int16 *)(a2 + 68);
if ( (int)v9 < (int)v3 || (v10 = *(int *)(a2 + 20), v10 < v9 + 14) )
{
if ( (net_debug & 8) != 0 )
{
v11 = syscall(186LL);
fprintf(stderr, "[%d]%s \x1B[01;34mip\x1B[0m ip size is unknown\n", v11, "ip_in");
}
return free_pkb(a2);
}
if ( v10 > v9 + 14 )
pkb_trim(a2, (unsigned int)(v9 + 14));
if ( (net_debug & 8) != 0 )
{
v12 = *(_DWORD *)(a2 + 78);
v13 = *(_DWORD *)(a2 + 82);
v14 = *(unsigned __int16 *)(a2 + 68);
v15 = syscall(186LL);
fprintf(
stderr,
"[%d]%s \x1B[01;34mip\x1B[0m %d.%d.%d.%d -> %d.%d.%d.%d(%d/%d bytes)\n",
v15,
"ip_in",
(unsigned __int8)v12,
BYTE1(v12),
BYTE2(v12),
HIBYTE(v12),
(unsigned __int8)v13,
BYTE1(v13),
BYTE2(v13),
HIBYTE(v13),
v3,
v14);
}
return func2(a2);
}

original_code:
void ip_in(struct netdev *dev, struct pkbuf *pkb)
{
 struct ether *ehdr = (struct ether *)pkb->pk_data;
 struct ip *iphdr = (struct ip *)ehdr->eth_data;
 int hlen;
 if (pkb->pk_type == 2) {
  do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""ip(l2) packet is not for us" "\n", (int)syscall(186), __FUNCTION__);} while (0);
  goto err_free_pkb;
 }
 if (pkb->pk_len < sizeof(struct ether) + sizeof(struct ip)) {
  do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""ip packet is too small" "\n", (int)syscall(186), __FUNCTION__);} while (0);
  goto err_free_pkb;
 }
 if (((iphdr)->ip_ver) != 4) {
  do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""ip packet is not version 4" "\n", (int)syscall(186), __FUNCTION__);} while (0);
  goto err_free_pkb;
 }
 hlen = ((iphdr)->ip_hlen << 2);
 if (hlen < sizeof(struct ip)) {
  do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""ip header is too small" "\n", (int)syscall(186), __FUNCTION__);} while (0);
  goto err_free_pkb;
 }
 if (ip_chksum((unsigned short *)iphdr, hlen) != 0) {
  do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""ip checksum is error" "\n", (int)syscall(186), __FUNCTION__);} while (0);
  goto err_free_pkb;
 }
 ip_ntoh(iphdr);
 if (iphdr->ip_len < hlen ||
  pkb->pk_len < sizeof(struct ether) + iphdr->ip_len) {
  do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""ip size is unknown" "\n", (int)syscall(186), __FUNCTION__);} while (0);
  goto err_free_pkb;
 }
 if (pkb->pk_len > sizeof(struct ether) + iphdr->ip_len)
  pkb_trim(pkb, sizeof(struct ether) + iphdr->ip_len);
 do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""%d.%d.%d.%d" " -> " "%d.%d.%d.%d" "(%d/%d bytes)" "\n", (int)syscall(186), __FUNCTION__, (iphdr->ip_src) & 0xff, ((iphdr->ip_src) >> 8) & 0xff, ((iphdr->ip_src) >> 16) & 0xff, ((iphdr->ip_src) >> 24) & 0xff, (iphdr->ip_dst) & 0xff, ((iphdr->ip_dst) >> 8) & 0xff, ((iphdr->ip_dst) >> 16) & 0xff, ((iphdr->ip_dst) >> 24) & 0xff, hlen, iphdr->ip_len);} while (0);
 ip_recv_route(pkb);
 return;
err_free_pkb:
 free_pkb(pkb);
}

variable_types:
pkb
struct pkbuf *

variable_types: struct ether { unsigned char eth_dst[6]; unsigned char eth_src[6]; unsigned short eth_pro; unsigned char eth_data[]; } *

variable_types: hlen int

user_defined_types: struct pkbuf { struct list_head pk_list; unsigned short pk_pro; unsigned short pk_type; int pk_len; int pk_refcnt; struct netdev *pk_indev; struct rtentry *pk_rtdst; struct sock *pk_sk; unsigned char pk_data[]; }

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

user_defined_types: struct socket_ops { int (*socket)(struct socket *, int); int (*close)(struct socket *); int (*accept)(struct socket *, struct socket *, struct sock_addr *); int (*listen)(struct socket *, int); int (*bind)(struct socket *, struct sock_addr *); int (*connect)(struct socket *, struct sock_addr *); int (*read)(struct socket *, void *, int); int (*write)(struct socket *, void *, int); int (*send)(struct socket *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct socket *); }

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


original_code:
void ip_send_dev(struct netdev *dev, struct pkbuf *pkb)
{
 struct arpentry *ae;
 unsigned int dst;
 struct rtentry *rt = pkb->pk_rtdst;
 if (rt->rt_flags & 0x00000001) {
  do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""To loopback" "\n", (int)syscall(186), __FUNCTION__);} while (0);
  netdev_tx(dev, pkb, pkb->pk_len - sizeof(struct ether),
     0x0800, dev->net_hwaddr);
  return;
 }
 if ((rt->rt_flags & 0x00000002) || rt->rt_metric > 0)
  dst = rt->rt_gw;
 else
  dst = ((struct ip *)((pkb)->pk_data + sizeof(struct ether)))->ip_dst;
 ae = arp_lookup(0x0800, dst);
 if (!ae) {
  do { if (net_debug & 0x00000004) fprintf(stderr, "[%d]%s " "\e[01;31m""arp""\e\[0m"" ""not found arp cache" "\n", (int)syscall(186), __FUNCTION__);} while (0);
  ae = arp_alloc();
  if (!ae) {
   do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""arp cache is full" "\n", (int)syscall(186), __FUNCTION__);} while (0);
   free_pkb(pkb);
   return;
  }
  ae->ae_ipaddr = dst;
  ae->ae_dev = dev;
  list_add_tail(&pkb->pk_list, &ae->ae_list);
  arp_request(ae);
 } else if (ae->ae_state == 2) {
  do { if (net_debug & 0x00000004) fprintf(stderr, "[%d]%s " "\e[01;31m""arp""\e\[0m"" ""arp entry is waiting" "\n", (int)syscall(186), __FUNCTION__);} while (0);
  list_add_tail(&pkb->pk_list, &ae->ae_list);
 } else {
  netdev_tx(dev, pkb, pkb->pk_len - sizeof(struct ether),
    0x0800, ae->ae_hwaddr);
 }
}

variable_types: struct arpentry { struct list_head { struct list_head *prev; } ae_list; struct netdev { int net_mtu; unsigned int net_ipaddr; unsigned int net_mask; unsigned char net_hwaddr[6]; unsigned char net_name[16]; struct netdev_ops { int (*xmit)(struct netdev *, struct pkbuf { struct list_head pk_list; unsigned short pk_pro; unsigned short pk_type; int pk_len; int pk_refcnt; struct netdev *pk_indev; struct rtentry { struct list_head rt_list; unsigned int rt_net; unsigned int rt_netmask; unsigned int rt_gw; unsigned int rt_flags; int rt_metric; struct netdev *rt_dev; } *pk_rtdst; struct sock { unsigned char protocol; struct sock_addr { unsigned int src_addr; unsigned int dst_addr; unsigned short src_port; unsigned short dst_port; } sk_addr; struct socket { unsigned int state; unsigned int family; unsigned int type; struct tapip_wait { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int notified; int dead; int sleep; } sleep; struct socket_ops { int (*socket)(struct socket *, int); int (*close)(struct socket *); int (*accept)(struct socket *, struct socket *, struct sock_addr *); int (*listen)(struct socket *, int); int (*bind)(struct socket *, struct sock_addr *); int (*connect)(struct socket *, struct sock_addr *); int (*read)(struct socket *, void *, int); int (*write)(struct socket *, void *, int); int (*send)(struct socket *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct socket *); } *ops; struct sock *sk; int refcnt; } *sock; struct sock_ops { void (*recv_notify)(struct sock *); void (*send_notify)(struct sock *); int (*send_pkb)(struct sock *, struct pkbuf *); int (*send_buf)(struct sock *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct sock *); int (*recv_buf)(struct sock *, char *, int); int (*hash)(struct sock *); void (*unhash)(struct sock *); int (*bind)(struct sock *, struct sock_addr *); int (*connect)(struct sock *, struct sock_addr *); int (*set_port)(struct sock *, unsigned short); int (*close)(struct sock *); int (*listen)(struct sock *, int); struct sock *(*accept)(struct sock *); } *ops; struct rtentry *sk_dst; struct list_head recv_queue; struct tapip_wait *recv_wait; unsigned int hash; struct hlist_node { struct hlist_node *next; struct hlist_node **pprev; } hash_list; int refcnt; } *pk_sk; unsigned char pk_data[]; } *); int (*init)(struct netdev *); void (*exit)(struct netdev *); } *net_ops; struct netstats { unsigned int rx_packets; unsigned int tx_packets; unsigned int rx_errors; unsigned int tx_errors; unsigned int rx_bytes; unsigned int tx_bytes; } net_stats; struct list_head net_list; } *ae_dev; int ae_retry; int ae_ttl; unsigned int ae_state; unsigned short ae_pro; unsigned int ae_ipaddr; unsigned char ae_hwaddr[6]; } *

user_defined_types: struct ether { unsigned char eth_dst[6]; unsigned char eth_src[6]; unsigned short eth_pro; unsigned char eth_data[]; }

user_defined_types: struct netdev { int net_mtu; unsigned int net_ipaddr; unsigned int net_mask; unsigned char net_hwaddr[6]; unsigned char net_name[16]; struct netdev_ops *net_ops; struct netstats net_stats; struct list_head net_list; }

user_defined_types: struct arpentry { struct list_head ae_list; struct netdev *ae_dev; int ae_retry; int ae_ttl; unsigned int ae_state; unsigned short ae_pro; unsigned int ae_ipaddr; unsigned char ae_hwaddr[6]; }

user_defined_types: struct ip { unsigned char ip_hlen; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_fragoff; unsigned char ip_ttl; unsigned char ip_pro; unsigned short ip_cksum; unsigned int ip_src; unsigned int ip_dst; unsigned char ip_data[]; }

user_defined_types: struct netdev_ops { int (*xmit)(struct netdev *, struct pkbuf *); int (*init)(struct netdev *); void (*exit)(struct netdev *); }


decompiled_code:
__int64 __fastcall ip_send_out(__int64 a1)
{
bool v2; // zf
int *v3; // rdi
__int64 result; // rax
unsigned int v5; // er14
unsigned int v6; // ebx
__int16 v7; // r13
char v8; // r12
__int64 v9; // rdx

v2 = *(_QWORD *)(a1 + 36) == 0LL;
*(_WORD *)(a1 + 16) = 2048;
if ( v2 && (int)rt_output() < 0 )
return free_pkb(a1);
ip_set_checksum(a1 + 66);
if ( (net_debug & 8) != 0 )
{
v5 = *(_DWORD *)(a1 + 78);
v6 = *(_DWORD *)(a1 + 82);
v7 = *(_WORD *)(a1 + 68);
v8 = *(_BYTE *)(a1 + 66);
v9 = syscall(186LL);
fprintf(
stderr,
"[%d]%s \x1B[01;34mip\x1B[0m %d.%d.%d.%d -> %d.%d.%d.%d(%d/%d bytes)\n",
v9,
"ip_send_out",
(unsigned __int8)v5,
BYTE1(v5),
BYTE2(v5),
HIBYTE(v5),
(unsigned __int8)v6,
BYTE1(v6),
BYTE2(v6),
HIBYTE(v6),
4 * (v8 & 0xFu),
(unsigned __int16)__ROL2__(v7, 8));
}
v3 = *(int **)(*(_QWORD *)(a1 + 36) + 40LL);
if ( (unsigned __int16)__ROL2__(*(_WORD *)(a1 + 68), 8) <= *v3 )
result = ip_send_dev((__int64)v3, a1);
else
result = ip_send_frag(v3, a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
bool v2; // zf
int *v3; // rdi
__int64 result; // rax
unsigned int v5; // er14
unsigned int v6; // ebx
__int16 v7; // r13
char v8; // r12
__int64 v9; // rdx

v2 = *(_QWORD *)(a1 + 36) == 0LL;
*(_WORD *)(a1 + 16) = 2048;
if ( v2 && (int)rt_output() < 0 )
return free_pkb(a1);
ip_set_checksum(a1 + 66);
if ( (net_debug & 8) != 0 )
{
v5 = *(_DWORD *)(a1 + 78);
v6 = *(_DWORD *)(a1 + 82);
v7 = *(_WORD *)(a1 + 68);
v8 = *(_BYTE *)(a1 + 66);
v9 = syscall(186LL);
fprintf(
stderr,
"[%d]%s \x1B[01;34mip\x1B[0m %d.%d.%d.%d -> %d.%d.%d.%d(%d/%d bytes)\n",
v9,
"ip_send_out",
(unsigned __int8)v5,
BYTE1(v5),
BYTE2(v5),
HIBYTE(v5),
(unsigned __int8)v6,
BYTE1(v6),
BYTE2(v6),
HIBYTE(v6),
4 * (v8 & 0xFu),
(unsigned __int16)__ROL2__(v7, 8));
}
v3 = *(int **)(*(_QWORD *)(a1 + 36) + 40LL);
if ( (unsigned __int16)__ROL2__(*(_WORD *)(a1 + 68), 8) <= *v3 )
result = func0((__int64)v3, a1);
else
result = ip_send_frag(v3, a1);
return result;
}

original_code:
void ip_send_out(struct pkbuf *pkb)
{
 struct ip *iphdr = ((struct ip *)((pkb)->pk_data + sizeof(struct ether)));
 pkb->pk_pro = 0x0800;
 if (!pkb->pk_rtdst && rt_output(pkb) < 0) {
  free_pkb(pkb);
  return;
 }
 ip_set_checksum(iphdr);
 do { if (net_debug & 0x00000008) fprintf(stderr, "[%d]%s " "\e[01;34m""ip""\e\[0m"" ""%d.%d.%d.%d" " -> " "%d.%d.%d.%d" "(%d/%d bytes)" "\n", (int)syscall(186), __FUNCTION__, (iphdr->ip_src) & 0xff, ((iphdr->ip_src) >> 8) & 0xff, ((iphdr->ip_src) >> 16) & 0xff, ((iphdr->ip_src) >> 24) & 0xff, (iphdr->ip_dst) & 0xff, ((iphdr->ip_dst) >> 8) & 0xff, ((iphdr->ip_dst) >> 16) & 0xff, ((iphdr->ip_dst) >> 24) & 0xff, ((iphdr)->ip_hlen << 2), _htons(iphdr->ip_len));} while (0);
 if (_htons(iphdr->ip_len) > pkb->pk_rtdst->rt_dev->net_mtu)
  ip_send_frag(pkb->pk_rtdst->rt_dev, pkb);
 else
  ip_send_dev(pkb->pk_rtdst->rt_dev, pkb);
}

variable_types: struct pkbuf { struct list_head { struct list_head *prev; } pk_list; unsigned short pk_pro; unsigned short pk_type; int pk_len; int pk_refcnt; struct netdev { int net_mtu; unsigned int net_ipaddr; unsigned int net_mask; unsigned char net_hwaddr[6]; unsigned char net_name[16]; struct netdev_ops { int (*xmit)(struct netdev *, struct pkbuf *); int (*init)(struct netdev *); void (*exit)(struct netdev *); } *net_ops; struct netstats { unsigned int rx_packets; unsigned int tx_packets; unsigned int rx_errors; unsigned int tx_errors; unsigned int rx_bytes; unsigned int tx_bytes; } net_stats; struct list_head net_list; } *pk_indev; struct rtentry { struct list_head rt_list; unsigned int rt_net; unsigned int rt_netmask; unsigned int rt_gw; unsigned int rt_flags; int rt_metric; struct netdev *rt_dev; } *pk_rtdst; struct sock { unsigned char protocol; struct sock_addr { unsigned int src_addr; unsigned int dst_addr; unsigned short src_port; unsigned short dst_port; } sk_addr; struct socket { unsigned int state; unsigned int family; unsigned int type; struct tapip_wait { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int notified; int dead; int sleep; } sleep; struct socket_ops { int (*socket)(struct socket *, int); int (*close)(struct socket *); int (*accept)(struct socket *, struct socket *, struct sock_addr *); int (*listen)(struct socket *, int); int (*bind)(struct socket *, struct sock_addr *); int (*connect)(struct socket *, struct sock_addr *); int (*read)(struct socket *, void *, int); int (*write)(struct socket *, void *, int); int (*send)(struct socket *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct socket *); } *ops; struct sock *sk; int refcnt; } *sock; struct sock_ops { void (*recv_notify)(struct sock *); void (*send_notify)(struct sock *); int (*send_pkb)(struct sock *, struct pkbuf *); int (*send_buf)(struct sock *, void *, int, struct sock_addr *); struct pkbuf *(*recv)(struct sock *); int (*recv_buf)(struct sock *, char *, int); int (*hash)(struct sock *); void (*unhash)(struct sock *); int (*bind)(struct sock *, struct sock_addr *); int (*connect)(struct sock *, struct sock_addr *); int (*set_port)(struct sock *, unsigned short); int (*close)(struct sock *); int (*listen)(struct sock *, int); struct sock *(*accept)(struct sock *); } *ops; struct rtentry *sk_dst; struct list_head recv_queue; struct tapip_wait *recv_wait; unsigned int hash; struct hlist_node { struct hlist_node *next; struct hlist_node **pprev; } hash_list; int refcnt; } *pk_sk; unsigned char pk_data[]; } *


original_code:
void ip_send_info(struct pkbuf *pkb, unsigned char tos, unsigned short len,
  unsigned char ttl, unsigned char pro, unsigned int dst)
{
 struct ip *iphdr = ((struct ip *)((pkb)->pk_data + sizeof(struct ether)));
 iphdr->ip_ver = 4;
 iphdr->ip_hlen = sizeof(struct ip) / 4;
 iphdr->ip_tos = tos;
 iphdr->ip_len = _htons(len);
 iphdr->ip_id = _htons(ipid++);
 iphdr->ip_fragoff = 0;
 iphdr->ip_ttl = ttl;
 iphdr->ip_pro = pro;
 iphdr->ip_dst = dst;
 ip_send_out(pkb);
}

variable_types:
tos
unsigned char

variable_types:
len
unsigned short

variable_types:
ttl
unsigned char

variable_types:
pro
unsigned char

user_defined_types: struct list_head { struct list_head *prev; }

user_defined_types: struct rtentry { struct list_head rt_list; unsigned int rt_net; unsigned int rt_netmask; unsigned int rt_gw; unsigned int rt_flags; int rt_metric; struct netdev *rt_dev; }

user_defined_types: struct netstats { unsigned int rx_packets; unsigned int tx_packets; unsigned int rx_errors; unsigned int tx_errors; unsigned int rx_bytes; unsigned int tx_bytes; }

user_defined_types: struct sock_addr { unsigned int src_addr; unsigned int dst_addr; unsigned short src_port; unsigned short dst_port; }

user_defined_types: struct hlist_node { struct hlist_node *next; struct hlist_node **pprev; }


decompiled_code:
__int64 tap_dev_init()
{
_DWORD *v0; // rbx
int v1; // eax
int *v2; // r8
_QWORD *v3; // rax
char *v4; // rdx

v0 = (_DWORD *)xmalloc(96LL);
tap = v0;
v1 = alloc_tap("tap0");
v2 = (int *)tap;
v0[22] = v1;
if ( v2[22] >= 0 )
{
if ( (int)setpersist_tap() >= 0 )
{
set_tap();
getname_tap(*((unsigned int *)tap + 22), (char *)tap + 18);
getmtu_tap((char *)tap + 18);
gethwaddr_tap(*((unsigned int *)tap + 22), (char *)tap + 12);
setipaddr_tap((char *)tap + 18, 33554442LL);
getipaddr_tap((char *)tap + 18, (char *)tap + 4);
setnetmask_tap((char *)tap + 18, 0xFFFFFFLL);
setup_tap((char *)tap + 18);
unset_tap();
v3 = tap;
v4 = (char *)tap + 72;
*((_QWORD *)tap + 10) = (char *)tap + 72;
v3[9] = v4;
return 0LL;
}
close(*((_DWORD *)tap + 22));
v2 = (int *)tap;
}
free(v2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func3()
{
_DWORD *v0; // rbx
int v1; // eax
int *v2; // r8
_QWORD *v3; // rax
char *v4; // rdx

v0 = (_DWORD *)xmalloc(96LL);
tap = v0;
v1 = alloc_tap("tap0");
v2 = (int *)tap;
v0[22] = v1;
if ( v2[22] >= 0 )
{
if ( (int)setpersist_tap() >= 0 )
{
set_tap();
getname_tap(*((unsigned int *)tap + 22), (char *)tap + 18);
getmtu_tap((char *)tap + 18);
gethwaddr_tap(*((unsigned int *)tap + 22), (char *)tap + 12);
setipaddr_tap((char *)tap + 18, 33554442LL);
getipaddr_tap((char *)tap + 18, (char *)tap + 4);
setnetmask_tap((char *)tap + 18, 0xFFFFFFLL);
setup_tap((char *)tap + 18);
unset_tap();
v3 = tap;
v4 = (char *)tap + 72;
*((_QWORD *)tap + 10) = (char *)tap + 72;
v3[9] = v4;
return 0LL;
}
close(*((_DWORD *)tap + 22));
v2 = (int *)tap;
}
free(v2);
return 0xFFFFFFFFLL;
}

original_code:
static int tap_dev_init(void)
{
 tap = xmalloc(sizeof(*tap));
 tap->fd = alloc_tap("tap0");
 if (tap->fd < 0)
  goto free_tap;
 if (setpersist_tap(tap->fd) < 0)
  goto close_tap;
 set_tap();
 getname_tap(tap->fd, tap->dev.net_name);
 getmtu_tap(tap->dev.net_name, &tap->dev.net_mtu);
 gethwaddr_tap(tap->fd, tap->dev.net_hwaddr);
 setipaddr_tap(tap->dev.net_name, 0x0200000a);
 getipaddr_tap(tap->dev.net_name, &tap->dev.net_ipaddr);
 setnetmask_tap(tap->dev.net_name, 0x00ffffff);
 setup_tap(tap->dev.net_name);
 unset_tap();
 list_init(&tap->dev.net_list);
 return 0;
close_tap:
 close(tap->fd);
free_tap:
 free(tap);
 return -1;
}

canonical_original_code:
static int tap_dev_init()
{
 tap = xmalloc(sizeof(*tap));
 tap->fd = alloc_tap("tap0");
 if (tap->fd < 0)
  goto free_tap;
 if (setpersist_tap(tap->fd) < 0)
  goto close_tap;
 set_tap();
 getname_tap(tap->fd, tap->dev.net_name);
 getmtu_tap(tap->dev.net_name, &tap->dev.net_mtu);
 gethwaddr_tap(tap->fd, tap->dev.net_hwaddr);
 setipaddr_tap(tap->dev.net_name, 0x0200000a);
 getipaddr_tap(tap->dev.net_name, &tap->dev.net_ipaddr);
 setnetmask_tap(tap->dev.net_name, 0x00ffffff);
 setup_tap(tap->dev.net_name);
 unset_tap();
 list_init(&tap->dev.net_list);
 return 0;
close_tap:
 close(tap->fd);
free_tap:
 free(tap);
 return -1;
}


decompiled_code:
void __noreturn veth_poll()
{
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

while ( 1 )
{
*(_DWORD *)&fds.events = 1;
fds.fd = *((_DWORD *)tap + 22);
if ( poll(&fds, 1uLL, -1) <= 0 )
perrx("poll /dev/net/tun");
veth_rx();
}
}

canonical_decompiled_code:
void __noreturn func7()
{
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

while ( 1 )
{
*(_DWORD *)&fds.events = 1;
fds.fd = *((_DWORD *)tap + 22);
if ( poll(&fds, 1uLL, -1) <= 0 )
perrx("poll /dev/net/tun");
func1();
}
}

original_code:
void veth_poll(void)
{
 struct pollfd pfd = {};
 int ret;
 while (1) {
  pfd.fd = tap->fd;
  pfd.events = 0x001;
  pfd.revents = 0;
  ret = poll(&pfd, 1, -1);
  if (ret <= 0)
   perrx("poll /dev/net/tun");
  veth_rx();
 }
}

canonical_original_code:
void veth_poll()
{
 struct pollfd pfd = {};
 int ret;
 while (1) {
  pfd.fd = tap->fd;
  pfd.events = 0x001;
  pfd.revents = 0;
  ret = poll(&pfd, 1, -1);
  if (ret <= 0)
   perrx("poll /dev/net/tun");
  veth_rx();
 }
}

variable_types: struct pollfd { int fd; short events; short revents; }

variable_types: ret int


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

result = netdev_alloc("veth", &veth_ops);
veth = result;
return result;
}

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

result = netdev_alloc("veth", &veth_ops);
veth = result;
return result;
}

original_code:
void veth_init(void)
{
 veth = netdev_alloc("veth", &veth_ops);
}

canonical_original_code:
void veth_init()
{
 veth = netdev_alloc("veth", &veth_ops);
}


decompiled_code:
__int64 veth_exit()
{
return netdev_free(veth);
}

canonical_decompiled_code:
__int64 func9()
{
return netdev_free(veth);
}

original_code:
void veth_exit(void)
{
 netdev_free(veth);
}

canonical_original_code:
void veth_exit()
{
 netdev_free(veth);
}


decompiled_code:
__int64 __fastcall new_frag(__int64 a1)
{
__int64 result; // rax
void **v2; // rcx
__int16 v3; // dx

result = xmalloc(72LL);
v2 = off_928;
*(_WORD *)result = *(_WORD *)(a1 + 4);
*(_DWORD *)(result + 4) = *(_DWORD *)(a1 + 12);
*(_DWORD *)(result + 8) = *(_DWORD *)(a1 + 16);
v3 = *(unsigned __int8 *)(a1 + 9);
*(_QWORD *)(result + 16) = 0LL;
*(_WORD *)(result + 12) = v3;
*(_QWORD *)(result + 24) = 0x1E00000000LL;
*(_DWORD *)(result + 32) = 0;
*(_QWORD *)(result + 40) = &frag_head;
*(_QWORD *)(result + 48) = v2;
*v2 = (void *)(result + 40);
off_928 = (void **)(result + 40);
*(_QWORD *)(result + 64) = result + 56;
*(_QWORD *)(result + 56) = result + 56;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
void **v2; // rcx
__int16 v3; // dx

result = xmalloc(72LL);
v2 = off_928;
*(_WORD *)result = *(_WORD *)(a1 + 4);
*(_DWORD *)(result + 4) = *(_DWORD *)(a1 + 12);
*(_DWORD *)(result + 8) = *(_DWORD *)(a1 + 16);
v3 = *(unsigned __int8 *)(a1 + 9);
*(_QWORD *)(result + 16) = 0LL;
*(_WORD *)(result + 12) = v3;
*(_QWORD *)(result + 24) = 0x1E00000000LL;
*(_DWORD *)(result + 32) = 0;
*(_QWORD *)(result + 40) = &frag_head;
*(_QWORD *)(result + 48) = v2;
*v2 = (void *)(result + 40);
off_928 = (void **)(result + 40);
*(_QWORD *)(result + 64) = result + 56;
*(_QWORD *)(result + 56) = result + 56;
return result;
}

original_code:
struct fragment *new_frag(struct ip *iphdr)
{
 struct fragment *frag;
 frag = xmalloc(sizeof(*frag));
 frag->frag_ttl = 30;
 frag->frag_id = iphdr->ip_id;
 frag->frag_src = iphdr->ip_src;
 frag->frag_dst = iphdr->ip_dst;
 frag->frag_pro = iphdr->ip_pro;
 frag->frag_hlen = 0;
 frag->frag_size = 0;
 frag->frag_rsize = 0;
 frag->frag_flags = 0;
 list_add(&frag->frag_list, &frag_head);
 list_init(&frag->frag_pkb);
 return frag;
}

variable_types: struct fragment { unsigned short frag_id; unsigned int frag_src; unsigned int frag_dst; unsigned short frag_pro; unsigned int frag_hlen; unsigned int frag_rsize; unsigned int frag_size; int frag_ttl; unsigned int frag_flags; struct list_head { struct list_head *prev; } frag_list; struct list_head frag_pkb; } *

user_defined_types: struct fragment { unsigned short frag_id; unsigned int frag_src; unsigned int frag_dst; unsigned short frag_pro; unsigned int frag_hlen; unsigned int frag_rsize; unsigned int frag_size; int frag_ttl; unsigned int frag_flags; struct list_head frag_list; struct list_head frag_pkb; }


decompiled_code:
void __fastcall free_list(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
static void free_list(struct list *list)
{
    free(list->data);
    free(list);
}

variable_types: struct list { unsigned int *data; unsigned long n; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v4; // r13
unsigned int v5; // eax
char *v6; // r15
unsigned __int64 v7; // rbp
_QWORD *v8; // rbp
_QWORD v10[5]; // [rsp+0h] [rbp-A8h] BYREF
char v11; // [rsp+28h] [rbp-80h] BYREF
__int64 v12[7]; // [rsp+38h] [rbp-70h] BYREF
char v13; // [rsp+70h] [rbp-38h] BYREF

v3 = 32LL;
v10[1] = 128LL;
v4 = (char *)v10;
v10[2] = 1024LL;
v10[3] = 0x100000LL;
v10[4] = 10485760LL;
v12[0] = 8LL;
v12[1] = 32LL;
v12[2] = 128LL;
v12[3] = 512LL;
v12[4] = 0x4000LL;
v12[5] = 0x40000LL;
v12[6] = 0x10000000LL;
v5 = time(0LL);
srand(v5);
while ( 1 )
{
v6 = (char *)v12;
v7 = 4LL;
while ( 1 )
{
printf("nitems: %lu, max_value: %lu\n", v3, v7);
v8 = generate_list(v3, v7);
test(v8, (void (__fastcall *)(void **, __int64 *, FILE *))&simple9_decode);
test(v8, (void (__fastcall *)(void **, __int64 *, FILE *))&simple9_decode_unrolled);
free_list(v8);
if ( v6 == &v13 )
break;
v7 = *(_QWORD *)v6;
v6 += 8;
}
v4 += 8;
if ( v4 == &v11 )
break;
v3 = *(_QWORD *)v4;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v4; // r13
unsigned int v5; // eax
char *v6; // r15
unsigned __int64 v7; // rbp
_QWORD *v8; // rbp
_QWORD v10[5]; // [rsp+0h] [rbp-A8h] BYREF
char v11; // [rsp+28h] [rbp-80h] BYREF
__int64 v12[7]; // [rsp+38h] [rbp-70h] BYREF
char v13; // [rsp+70h] [rbp-38h] BYREF

v3 = 32LL;
v10[1] = 128LL;
v4 = (char *)v10;
v10[2] = 1024LL;
v10[3] = 0x100000LL;
v10[4] = 10485760LL;
v12[0] = 8LL;
v12[1] = 32LL;
v12[2] = 128LL;
v12[3] = 512LL;
v12[4] = 0x4000LL;
v12[5] = 0x40000LL;
v12[6] = 0x10000000LL;
v5 = time(0LL);
srand(v5);
while ( 1 )
{
v6 = (char *)v12;
v7 = 4LL;
while ( 1 )
{
printf("nitems: %lu, max_value: %lu\n", v3, v7);
v8 = generate_list(v3, v7);
func1(v8, (void (__fastcall *)(void **, __int64 *, FILE *))&simple9_decode);
func1(v8, (void (__fastcall *)(void **, __int64 *, FILE *))&simple9_decode_unrolled);
func0(v8);
if ( v6 == &v13 )
break;
v7 = *(_QWORD *)v6;
v6 += 8;
}
v4 += 8;
if ( v4 == &v11 )
break;
v3 = *(_QWORD *)v4;
}
return 0;
}

original_code:
int main()
{
    struct list *list;
    size_t test_nitems[] = {32, 128, 1024, 1048576, 10485760};
    size_t test_max_value[] = {4, 8, 32, 128, 512, 16384, 262144, 268435456};
    size_t i;
    size_t j;
    srand(time(((void *)0)));
    for (i = 0; i < sizeof test_nitems / sizeof test_nitems[0]; i++) {
        for (j = 0; j < sizeof test_max_value / sizeof test_max_value[0]; j++) {
            printf("nitems: %lu, max_value: %lu\n",
                   (unsigned long)test_nitems[i],
                   (unsigned long)test_max_value[j]);
            list = generate_list(test_nitems[i], test_max_value[j]);
            test(list, simple9_decode);
            test(list, simple9_decode_unrolled);
            free_list(list);
        }
    }
    return 0;
}

canonical_original_code:
int main()
{
    struct list *list;
    unsigned long test_nitems[] = {32, 128, 1024, 1048576, 10485760};
    unsigned long test_max_value[] = {4, 8, 32, 128, 512, 16384, 262144, 268435456};
    unsigned long i;
    unsigned long j;
    srand(time(((void *)0)));
    for (i = 0; i < sizeof test_nitems / sizeof test_nitems[0]; i++) {
        for (j = 0; j < sizeof test_max_value / sizeof test_max_value[0]; j++) {
            printf("nitems: %lu, max_value: %lu\n",
                   (unsigned long)test_nitems[i],
                   (unsigned long)test_max_value[j]);
            list = generate_list(test_nitems[i], test_max_value[j]);
            test(list, simple9_decode);
            test(list, simple9_decode_unrolled);
            free_list(list);
        }
    }
    return 0;
}

variable_types:
i
unsigned long

variable_types:
j
unsigned long

user_defined_types: struct list { unsigned int *data; unsigned long n; }


repo: choueric/doc

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)CU_initialize_registry(argc, argv, envp) )
{
fwrite(" Initialization of Test Registry failed\n", 1uLL, 0x28uLL, stderr);
exit(1);
}
test_maxi_AddSuites();
test_mini_AddSuites();
CU_basic_set_mode(2LL);
CU_basic_run_tests();
CU_cleanup_registry();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 if(CU_initialize_registry()){
  fprintf(stderr, " Initialization of Test Registry failed\n");
  exit(1);
 }
 test_maxi_AddSuites();
 test_mini_AddSuites();
 CU_basic_set_mode(CU_BRM_VERBOSE);
 CU_basic_run_tests();
 CU_cleanup_registry();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


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

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

original_code:
static int suite_success_init(void)
{
 return 0;
}

canonical_original_code:
static int suite_success_init()
{
 return 0;
}


decompiled_code:
// attributes: thunk
__int64 suite_success_clean()
{
return suite_success_init();
}

canonical_decompiled_code:
__int64 func1()
{
return func0();
}

original_code:
static int suite_success_clean(void)
{
 return 0;
}

canonical_original_code:
static int suite_success_clean()
{
 return 0;
}


testInterILJ

decompiled_code:
__int64 testInterILJ()
{
int v0; // eax
int v1; // eax
int v2; // eax

v0 = inter_maxi(1LL, 2LL);
CU_assertImplementation(v0 == 2, 49LL, "CU_ASSERT_EQUAL(inter_maxi(1, 2),2)", "test_maxi.c", &unk_531, 0LL);
v1 = inter_maxi(0xFFFFFFFFLL, 0LL);
CU_assertImplementation(v1 == 0, 50LL, "CU_ASSERT_EQUAL(inter_maxi(-1, 0),0)", "test_maxi.c", &unk_531, 0LL);
v2 = inter_maxi(4294967294LL, 0xFFFFFFFFLL);
return CU_assertImplementation(v2 == -1, 51LL, "CU_ASSERT_EQUAL(inter_maxi(-2, -1),-1)", "test_maxi.c", &unk_531, 0LL);
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
int v1; // eax
int v2; // eax

v0 = inter_maxi(1LL, 2LL);
CU_assertImplementation(v0 == 2, 49LL, "CU_ASSERT_EQUAL(inter_maxi(1, 2),2)", "test_maxi.c", &unk_531, 0LL);
v1 = inter_maxi(0xFFFFFFFFLL, 0LL);
CU_assertImplementation(v1 == 0, 50LL, "CU_ASSERT_EQUAL(inter_maxi(-1, 0),0)", "test_maxi.c", &unk_531, 0LL);
v2 = inter_maxi(4294967294LL, 0xFFFFFFFFLL);
return CU_assertImplementation(v2 == -1, 51LL, "CU_ASSERT_EQUAL(inter_maxi(-2, -1),-1)", "test_maxi.c", &unk_531, 0LL);
}

original_code:
static void testInterILJ()
{
 { CU_assertImplementation(((inter_maxi(1, 2)) == (2)), 49, ("CU_ASSERT_EQUAL(" "inter_maxi(1, 2)" "," "2" ")"), "test_maxi.c", "", 0); };
 { CU_assertImplementation(((inter_maxi(-1, 0)) == (0)), 50, ("CU_ASSERT_EQUAL(" "inter_maxi(-1, 0)" "," "0" ")"), "test_maxi.c", "", 0); };
 { CU_assertImplementation(((inter_maxi(-2, -1)) == (-1)), 51, ("CU_ASSERT_EQUAL(" "inter_maxi(-2, -1)" "," "-1" ")"), "test_maxi.c", "", 0); };
}


testInterIGJ

decompiled_code:
__int64 testInterIGJ()
{
int v0; // eax
int v1; // eax
int v2; // eax

v0 = inter_maxi(2LL, 1LL);
CU_assertImplementation(v0 == 2, 42LL, "CU_ASSERT_EQUAL(inter_maxi(2, 1),2)", "test_maxi.c", &unk_531, 0LL);
v1 = inter_maxi(0LL, 0xFFFFFFFFLL);
CU_assertImplementation(v1 == 0, 43LL, "CU_ASSERT_EQUAL(inter_maxi(0, -1),0)", "test_maxi.c", &unk_531, 0LL);
v2 = inter_maxi(0xFFFFFFFFLL, 4294967294LL);
return CU_assertImplementation(v2 == -1, 44LL, "CU_ASSERT_EQUAL(inter_maxi(-1, -2),-1)", "test_maxi.c", &unk_531, 0LL);
}

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

v0 = inter_maxi(2LL, 1LL);
CU_assertImplementation(v0 == 2, 42LL, "CU_ASSERT_EQUAL(inter_maxi(2, 1),2)", "test_maxi.c", &unk_531, 0LL);
v1 = inter_maxi(0LL, 0xFFFFFFFFLL);
CU_assertImplementation(v1 == 0, 43LL, "CU_ASSERT_EQUAL(inter_maxi(0, -1),0)", "test_maxi.c", &unk_531, 0LL);
v2 = inter_maxi(0xFFFFFFFFLL, 4294967294LL);
return CU_assertImplementation(v2 == -1, 44LL, "CU_ASSERT_EQUAL(inter_maxi(-1, -2),-1)", "test_maxi.c", &unk_531, 0LL);
}

original_code:
static void testInterIGJ()
{
 { CU_assertImplementation(((inter_maxi(2, 1)) == (2)), 42, ("CU_ASSERT_EQUAL(" "inter_maxi(2, 1)" "," "2" ")"), "test_maxi.c", "", 0); };
 { CU_assertImplementation(((inter_maxi(0, -1)) == (0)), 43, ("CU_ASSERT_EQUAL(" "inter_maxi(0, -1)" "," "0" ")"), "test_maxi.c", "", 0); };
 { CU_assertImplementation(((inter_maxi(-1, -2)) == (-1)), 44, ("CU_ASSERT_EQUAL(" "inter_maxi(-1, -2)" "," "-1" ")"), "test_maxi.c", "", 0); };
}


testInterIQJ

decompiled_code:
__int64 testInterIQJ()
{
int v0; // eax
int v1; // eax

v0 = inter_maxi(1LL, 1LL);
CU_assertImplementation(v0 == 1, 36LL, "CU_ASSERT_EQUAL(inter_maxi(1, 1),1)", "test_maxi.c", &unk_531, 0LL);
v1 = inter_maxi(0LL, 0LL);
return CU_assertImplementation(v1 == 0, 37LL, "CU_ASSERT_EQUAL(inter_maxi(0, -0),0)", "test_maxi.c", &unk_531, 0LL);
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
int v1; // eax

v0 = inter_maxi(1LL, 1LL);
CU_assertImplementation(v0 == 1, 36LL, "CU_ASSERT_EQUAL(inter_maxi(1, 1),1)", "test_maxi.c", &unk_531, 0LL);
v1 = inter_maxi(0LL, 0LL);
return CU_assertImplementation(v1 == 0, 37LL, "CU_ASSERT_EQUAL(inter_maxi(0, -0),0)", "test_maxi.c", &unk_531, 0LL);
}

original_code:
static void testInterIQJ()
{
 { CU_assertImplementation(((inter_maxi(1, 1)) == (1)), 36, ("CU_ASSERT_EQUAL(" "inter_maxi(1, 1)" "," "1" ")"), "test_maxi.c", "", 0); };
 { CU_assertImplementation(((inter_maxi(0, -0)) == (0)), 37, ("CU_ASSERT_EQUAL(" "inter_maxi(0, -0)" "," "0" ")"), "test_maxi.c", "", 0); };
}


decompiled_code:
__int64 test_maxi_AddSuites()
{
__int64 result; // rax
const char *v1; // rax

if ( !CU_get_registry() )
_assert_fail("NULL != CU_get_registry()", "test_maxi.c", 0x60u, "test_maxi_AddSuites");
if ( (unsigned int)CU_is_test_running() )
_assert_fail("!CU_is_test_running()", "test_maxi.c", 0x61u, "test_maxi_AddSuites");
result = CU_register_suites(&suites);
if ( (_DWORD)result )
{
v1 = (const char *)CU_get_error_msg();
fprintf(stderr, "register suites failed - %s", v1);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
const char *v1; // rax

if ( !CU_get_registry() )
_assert_fail("NULL != CU_get_registry()", "test_maxi.c", 0x60u, "test_maxi_AddSuites");
if ( (unsigned int)CU_is_test_running() )
_assert_fail("!CU_is_test_running()", "test_maxi.c", 0x61u, "test_maxi_AddSuites");
result = CU_register_suites(&suites);
if ( (_DWORD)result )
{
v1 = (const char *)CU_get_error_msg();
fprintf(stderr, "register suites failed - %s", v1);
exit(1);
}
return result;
}

original_code:
void test_maxi_AddSuites(void)
{
 ((void) sizeof ((((void *)0) != CU_get_registry()) ? 1 : 0), __extension__ ({ if (((void *)0) != CU_get_registry()) ; else __assert_fail ("NULL != CU_get_registry()", "test_maxi.c", 96, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!CU_is_test_running()) ? 1 : 0), __extension__ ({ if (!CU_is_test_running()) ; else __assert_fail ("!CU_is_test_running()", "test_maxi.c", 97, __extension__ __PRETTY_FUNCTION__); }));
 if(CUE_SUCCESS != CU_register_suites(suites)){
  fprintf(stderr, "register suites failed - %s", CU_get_error_msg());
  exit(1);
 }
}

canonical_original_code:
void test_maxi_AddSuites()
{
 ((void) sizeof ((((void *)0) != CU_get_registry()) ? 1 : 0), __extension__ ({ if (((void *)0) != CU_get_registry()) ; else __assert_fail ("NULL != CU_get_registry()", "test_maxi.c", 96, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!CU_is_test_running()) ? 1 : 0), __extension__ ({ if (!CU_is_test_running()) ; else __assert_fail ("!CU_is_test_running()", "test_maxi.c", 97, __extension__ __PRETTY_FUNCTION__); }));
 if(CUE_SUCCESS != CU_register_suites(suites)){
  fprintf(stderr, "register suites failed - %s", CU_get_error_msg());
  exit(1);
 }
}


decompiled_code:
__int64 test_mini_AddSuites()
{
__int64 result; // rax
const char *v1; // rax

if ( !CU_get_registry() )
_assert_fail("NULL != CU_get_registry()", "test_mini.c", 0x46u, "test_mini_AddSuites");
if ( (unsigned int)CU_is_test_running() )
_assert_fail("!CU_is_test_running()", "test_mini.c", 0x47u, "test_mini_AddSuites");
result = CU_register_suites(&suites);
if ( (_DWORD)result )
{
v1 = (const char *)CU_get_error_msg();
fprintf(stderr, "register suites failed - %s", v1);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
const char *v1; // rax

if ( !CU_get_registry() )
_assert_fail("NULL != CU_get_registry()", "test_mini.c", 0x46u, "test_mini_AddSuites");
if ( (unsigned int)CU_is_test_running() )
_assert_fail("!CU_is_test_running()", "test_mini.c", 0x47u, "test_mini_AddSuites");
result = CU_register_suites(&suites);
if ( (_DWORD)result )
{
v1 = (const char *)CU_get_error_msg();
fprintf(stderr, "register suites failed - %s", v1);
exit(1);
}
return result;
}

original_code:
void test_mini_AddSuites(void)
{
 ((void) sizeof ((((void *)0) != CU_get_registry()) ? 1 : 0), __extension__ ({ if (((void *)0) != CU_get_registry()) ; else __assert_fail ("NULL != CU_get_registry()", "test_mini.c", 70, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!CU_is_test_running()) ? 1 : 0), __extension__ ({ if (!CU_is_test_running()) ; else __assert_fail ("!CU_is_test_running()", "test_mini.c", 71, __extension__ __PRETTY_FUNCTION__); }));
 if(CUE_SUCCESS != CU_register_suites(suites)){
  fprintf(stderr, "register suites failed - %s", CU_get_error_msg());
  exit(1);
 }
}

canonical_original_code:
void test_mini_AddSuites()
{
 ((void) sizeof ((((void *)0) != CU_get_registry()) ? 1 : 0), __extension__ ({ if (((void *)0) != CU_get_registry()) ; else __assert_fail ("NULL != CU_get_registry()", "test_mini.c", 70, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((!CU_is_test_running()) ? 1 : 0), __extension__ ({ if (!CU_is_test_running()) ; else __assert_fail ("!CU_is_test_running()", "test_mini.c", 71, __extension__ __PRETTY_FUNCTION__); }));
 if(CUE_SUCCESS != CU_register_suites(suites)){
  fprintf(stderr, "register suites failed - %s", CU_get_error_msg());
  exit(1);
 }
}


repo: choueric/tools

decompiled_code:
__int64 __fastcall check_file(char *file)
{
void *v2; // r13
int v3; // eax
int v4; // er12

if ( !is_file(file) )
return 0LL;
v2 = malloc(0x64uLL);
if ( v2 )
{
v3 = open(file, 2);
v4 = v3;
if ( v3 < 0 )
{
printf("open %s failed\n", file);
}
else if ( read(v3, v2, 0x64uLL) < 0 )
{
printf("read %s failed\n", file);
}
else
{
if ( close(v4) >= 0 )
return 0LL;
printf("close %s failed\n", file);
}
perror(" ");
exit(1);
}
puts("malloc failed");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *file)
{
void *v2; // r13
int v3; // eax
int v4; // er12

if ( !func7(file) )
return 0LL;
v2 = malloc(0x64uLL);
if ( v2 )
{
v3 = open(file, 2);
v4 = v3;
if ( v3 < 0 )
{
printf("open %s failed\n", file);
}
else if ( read(v3, v2, 0x64uLL) < 0 )
{
printf("read %s failed\n", file);
}
else
{
if ( close(v4) >= 0 )
return 0LL;
printf("close %s failed\n", file);
}
perror(" ");
exit(1);
}
puts("malloc failed");
return 1LL;
}

original_code:
static int check_file(char *file, void *data)
{
 int fd;
 char *buf;
 struct stat statbuf;
 int size;
 if (!is_file(file))
  return 0;
 size = 100;
 buf = malloc(size);
 if (buf == ((void *)0)) {
  printf("malloc failed\n");
  return 1;
 }
 fd = open(file, 02);
 if (fd < 0) {
  printf("open %s failed\n", file);
  perror("    ");
  exit(1);
 }
 if (read(fd, buf, size) < 0) {
  printf("read %s failed\n", file);
  perror("    ");
  exit(1);
 }
 if (close(fd) < 0) {
  printf("close %s failed\n", file);
  perror("    ");
  exit(1);
 }
 return 0;
}

variable_types:
file
char *

variable_types:
data
void *

variable_types: fd int

variable_types:
buf
char *

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

variable_types: size int

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:
_BOOL8 __fastcall is_special_dir(unsigned __int8 *a1)
{
_BOOL8 result; // rax
int v2; // eax

if ( *a1 != 46 || (result = 1LL, a1[1]) )
{
v2 = *a1 - 46;
if ( *a1 == 46 && (v2 = a1[1] - 46, a1[1] == 46) )
result = a1[2] == 0;
else
result = v2 == 0;
}
return result;
}

original_code:
static int is_special_dir(const char *path)
{
 return strcmp(path, ".") == 0 || strcmp(path, "..") == 0;
}

canonical_original_code:
static int is_special_dir(char *path)
{
 return strcmp(path, ".") == 0 || strcmp(path, "..") == 0;
}

variable_types:
path
char *


decompiled_code:
char *__fastcall get_file_path(char *s, char *src, char *dest)
{
char *v4; // rbx

v4 = stpcpy(dest, s);
if ( dest[strlen(s) - 1] != 47 )
*(_WORD *)v4 = 47;
return strcat(dest, src);
}

canonical_decompiled_code:
char *__fastcall func11(char *s, char *src, char *dest)
{
char *v4; // rbx

v4 = stpcpy(dest, s);
if ( dest[strlen(s) - 1] != 47 )
*(_WORD *)v4 = 47;
return strcat(dest, src);
}

original_code:
void get_file_path(const char *path, const char *filename, char *file_path)
{
 strcpy(file_path, path);
 if (file_path[strlen(path) - 1] != '/')
  strcat(file_path, "/");
 strcat(file_path, filename);
}

canonical_original_code:
void get_file_path(char *path, char *filename, char *file_path)
{
 strcpy(file_path, path);
 if (file_path[strlen(path) - 1] != '/')
  strcat(file_path, "/");
 strcat(file_path, filename);
}

variable_types:
filename
char *


decompiled_code:
int __fastcall byte_bin_str(unsigned __int8 a1, char *a2, size_t a3)
{
return snprintf(a2, a3, "%s,%s", &bit_rep[5 * (a1 >> 4)], &bit_rep[5 * (a1 & 0xF)]);
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int8 a1, char *a2, size_t a3)
{
return snprintf(a2, a3, "%s,%s", &bit_rep[5 * (a1 >> 4)], &bit_rep[5 * (a1 & 0xF)]);
}

original_code:
static int byte_bin_str(uint8_t byte, char *str, size_t str_size)
{
    return snprintf(str, str_size, "%s,%s", bit_rep[byte >> 4], bit_rep[byte & 0x0F]);
}

canonical_original_code:
static int byte_bin_str(unsigned char byte, char *str, unsigned long str_size)
{
    return snprintf(str, str_size, "%s,%s", bit_rep[byte >> 4], bit_rep[byte & 0x0F]);
}

variable_types:
byte
unsigned char

variable_types:
str
char *


hexdump

decompiled_code:
void __fastcall hexdump(__int64 a1, unsigned __int64 a2, int a3)
{
fhexdump(stderr, a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, unsigned __int64 a2, int a3)
{
func2(stderr, a1, a2, a3);
}

original_code:
void hexdump(uint8_t *buf, size_t nbytes, hexdump_flag_t flag)
{
 return fhexdump(stderr, buf, nbytes, flag);
}

canonical_original_code:
void hexdump(unsigned char *buf, unsigned long nbytes, enum hexdump_flag_t flag)
{
 return fhexdump(stderr, buf, nbytes, flag);
}

variable_types:
buf
unsigned char *

variable_types:
nbytes
unsigned long

variable_types: enum hexdump_flag_t { HEXDUMP_HEX_1=0, HEXDUMP_HEX_2=1, HEXDUMP_DEC_1=2, HEXDUMP_DEC_2=3, HEXDUMP_OCT_1=4, HEXDUMP_OCT_2=5, HEXDUMP_CHAR=6 }


original_code:
const char *bin_str(uint8_t *buf, size_t nbytes, char *str, size_t str_size)
{
 int i, n;
 ((((void *)0) != str && 0 != str_size) ? (void) (0) : __assert_fail ("NULL != str && 0 != str_size", "print.c", 108, __extension__ __PRETTY_FUNCTION__));
 ((((void *)0) != buf && 0 != nbytes) ? (void) (0) : __assert_fail ("NULL != buf && 0 != nbytes", "print.c", 109, __extension__ __PRETTY_FUNCTION__));
 for (i = 0, n = 0; i < (nbytes-1) && n < str_size; i++) {
  n += byte_bin_str(buf[i], str + n, str_size - n);
  str[n++] = ' ';
 }
 if (n < str_size)
  byte_bin_str(buf[i], str + n, str_size - n);
 return str;
}

canonical_original_code:
char *bin_str(unsigned char *buf, unsigned long nbytes, char *str, unsigned long str_size)
{
 int i; int n;
 ((((void *)0) != str && 0 != str_size) ? (void) (0) : __assert_fail ("NULL != str && 0 != str_size", "print.c", 108, __extension__ __PRETTY_FUNCTION__));
 ((((void *)0) != buf && 0 != nbytes) ? (void) (0) : __assert_fail ("NULL != buf && 0 != nbytes", "print.c", 109, __extension__ __PRETTY_FUNCTION__));
 for (i = 0, n = 0; i < (nbytes-1) && n < str_size; i++) {
  n += byte_bin_str(buf[i], str + n, str_size - n);
  str[n++] = ' ';
 }
 if (n < str_size)
  byte_bin_str(buf[i], str + n, str_size - n);
 return str;
}

variable_types: i int

variable_types: n int


original_code:
const char *hex_str(uint8_t *buf, size_t nbytes, char *str, size_t str_size)
{
 int i, n;
 ((((void *)0) != str && 0 != str_size) ? (void) (0) : __assert_fail ("NULL != str && 0 != str_size", "print.c", 126, __extension__ __PRETTY_FUNCTION__));
 ((((void *)0) != buf && 0 != nbytes) ? (void) (0) : __assert_fail ("NULL != buf && 0 != nbytes", "print.c", 127, __extension__ __PRETTY_FUNCTION__));
 for (i = 0, n = 0; i < (nbytes-1) && n < str_size; i++) {
  n += snprintf(str + n, str_size - n, "%02x", buf[i]);
  str[n++] = ' ';
 }
 if (n < str_size)
  snprintf(str + n, str_size - n, "%02x", buf[i]);
 return str;
}

canonical_original_code:
char *hex_str(unsigned char *buf, unsigned long nbytes, char *str, unsigned long str_size)
{
 int i; int n;
 ((((void *)0) != str && 0 != str_size) ? (void) (0) : __assert_fail ("NULL != str && 0 != str_size", "print.c", 126, __extension__ __PRETTY_FUNCTION__));
 ((((void *)0) != buf && 0 != nbytes) ? (void) (0) : __assert_fail ("NULL != buf && 0 != nbytes", "print.c", 127, __extension__ __PRETTY_FUNCTION__));
 for (i = 0, n = 0; i < (nbytes-1) && n < str_size; i++) {
  n += snprintf(str + n, str_size - n, "%02x", buf[i]);
  str[n++] = ' ';
 }
 if (n < str_size)
  snprintf(str + n, str_size - n, "%02x", buf[i]);
 return str;
}


decompiled_code:
int __fastcall console_enter_raw(struct termios *termios_p)
{
int result; // eax
__m128i v2; // xmm0
__m128i v3; // xmm1
__m128i v4; // xmm2
speed_t v5; // eax

result = tcgetattr(0, termios_p);
if ( result >= 0 )
{
v2 = _mm_loadu_si128((const __m128i *)termios_p);
v3 = _mm_loadu_si128((const __m128i *)&termios_p->c_line);
v4 = _mm_loadu_si128((const __m128i *)&termios_p->c_cc[15]);
*(_QWORD *)&termios_p[1].c_cc[31] = *(_QWORD *)&termios_p->c_cc[31];
v5 = termios_p->c_ospeed;
*(__m128i *)&termios_p[1].c_iflag = v2;
termios_p[1].c_lflag &= 0xFFFFFFF5;
termios_p[1].c_ospeed = v5;
*(__m128i *)&termios_p[1].c_line = v3;
*(__m128i *)&termios_p[1].c_cc[15] = v4;
result = tcsetattr(0, 0, termios_p + 1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(struct termios *termios_p)
{
int result; // eax
__m128i v2; // xmm0
__m128i v3; // xmm1
__m128i v4; // xmm2
speed_t v5; // eax

result = tcgetattr(0, termios_p);
if ( result >= 0 )
{
v2 = _mm_loadu_si128((const __m128i *)termios_p);
v3 = _mm_loadu_si128((const __m128i *)&termios_p->c_line);
v4 = _mm_loadu_si128((const __m128i *)&termios_p->c_cc[15]);
*(_QWORD *)&termios_p[1].c_cc[31] = *(_QWORD *)&termios_p->c_cc[31];
v5 = termios_p->c_ospeed;
*(__m128i *)&termios_p[1].c_iflag = v2;
termios_p[1].c_lflag &= 0xFFFFFFF5;
termios_p[1].c_ospeed = v5;
*(__m128i *)&termios_p[1].c_line = v3;
*(__m128i *)&termios_p[1].c_cc[15] = v4;
result = tcsetattr(0, 0, termios_p + 1);
}
return result;
}

original_code:
int console_enter_raw(console_t *con)
{
 int ret;
    if ( (ret = tcgetattr(0, &con->oldt)) < 0)
  return ret;
    con->newt = con->oldt;
    con->newt.c_lflag &= ~(0000002 | 0000010);
    return tcsetattr(0, 0, &con->newt);
}

canonical_original_code:
int console_enter_raw(struct console_t *con)
{
 int ret;
    if ( (ret = tcgetattr(0, &con->oldt)) < 0)
  return ret;
    con->newt = con->oldt;
    con->newt.c_lflag &= ~(0000002 | 0000010);
    return tcsetattr(0, 0, &con->newt);
}

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

variable_types: ret int

user_defined_types: struct console_t { struct termios oldt; }


decompiled_code:
int __fastcall console_leave_raw(struct termios *termios_p)
{
return tcsetattr(0, 0, termios_p);
}

canonical_decompiled_code:
int __fastcall func8(struct termios *termios_p)
{
return tcsetattr(0, 0, termios_p);
}

original_code:
int console_leave_raw(console_t *con)
{
    return tcsetattr(0, 0, &con->oldt);
}

canonical_original_code:
int console_leave_raw(struct console_t *con)
{
    return tcsetattr(0, 0, &con->oldt);
}

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


decompiled_code:
int console_restore()
{
int result; // eax
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

result = tcgetattr(0, &v1);
if ( result >= 0 )
{
v1.c_lflag |= 0xAu;
result = tcsetattr(0, 0, &v1);
}
return result;
}

canonical_decompiled_code:
int func9()
{
int result; // eax
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

result = tcgetattr(0, &v1);
if ( result >= 0 )
{
v1.c_lflag |= 0xAu;
result = tcsetattr(0, 0, &v1);
}
return result;
}

original_code:
int console_restore()
{
 int ret;
 struct termios t;
    if ( (ret = tcgetattr(0, &t)) < 0)
  return ret;
    t.c_lflag |= (0000002 | 0000010);
    return tcsetattr(0, 0, &t);
}

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


decompiled_code:
__int64 __fastcall dec_ratio(_DWORD *a1)
{
__int64 result; // rax

result = (unsigned int)*a1;
if ( (_DWORD)result )
{
result = (unsigned int)(result - 1);
*a1 = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1)
{
__int64 result; // rax

result = (unsigned int)*a1;
if ( (_DWORD)result )
{
result = (unsigned int)(result - 1);
*a1 = result;
}
return result;
}

original_code:
static inline void dec_ratio(int *p)
{
 int v = *p;
 if (v == 0)
  return;
 else
  *p = v-1;
}

variable_types:
p
int *

variable_types: v int


decompiled_code:
__int64 __fastcall inc_ratio(_DWORD *a1)
{
__int64 result; // rax

result = (unsigned int)*a1;
if ( (_DWORD)result != 12 )
{
result = (unsigned int)(result + 1);
*a1 = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1)
{
__int64 result; // rax

result = (unsigned int)*a1;
if ( (_DWORD)result != 12 )
{
result = (unsigned int)(result + 1);
*a1 = result;
}
return result;
}

original_code:
static inline void inc_ratio(int *p)
{
 int v = *p;
 if (v == 12)
  return;
 else
  *p = v+1;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
char v4; // al
unsigned int v6; // [rsp+Ch] [rbp-8Ch] BYREF
struct termios termios_p; // [rsp+10h] [rbp-88h] BYREF

v6 = 0;
if ( argc > 1 )
{
v3 = argv[1];
if ( *(_WORD *)v3 == 29229 && !v3[2] )
return console_restore(argc, argv, envp);
}
puts("Press <j> to decrease, <k> to increase, <enter> quit");
console_enter_raw(&termios_p);
while ( 1 )
{
v4 = fgetc(_bss_start);
if ( v4 == -1 || v4 == 10 )
break;
if ( v4 == 106 )
{
dec_ratio(&v6, argv);
}
else if ( v4 == 107 )
{
inc_ratio(&v6);
}
argv = (const char **)v6;
printf("ratio = %d\n", v6);
}
console_leave_raw(&termios_p);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
char v4; // al
unsigned int v6; // [rsp+Ch] [rbp-8Ch] BYREF
struct termios termios_p; // [rsp+10h] [rbp-88h] BYREF

v6 = 0;
if ( argc > 1 )
{
v3 = argv[1];
if ( *(_WORD *)v3 == 29229 && !v3[2] )
return func9(argc, argv, envp);
}
puts("Press <j> to decrease, <k> to increase, <enter> quit");
func7(&termios_p);
while ( 1 )
{
v4 = fgetc(_bss_start);
if ( v4 == -1 || v4 == 10 )
break;
if ( v4 == 106 )
{
func10(&v6, argv);
}
else if ( v4 == 107 )
{
func11(&v6);
}
argv = (const char **)v6;
printf("ratio = %d\n", v6);
}
func8(&termios_p);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 char c = 0;
 int ratio = 0;
 console_t con;
 if (argc >= 2 && !strcmp(argv[1], "-r"))
  return console_restore();
 printf("Press <j> to decrease, <k> to increase, <enter> quit\n");
 console_enter_raw(&con);
 while ( ((c = fgetc(stdin)) != (-1)) && c != '\n') {
  switch (c) {
  case 'j': dec_ratio(&ratio); break;
  case 'k': inc_ratio(&ratio); break;
  default: break;
  }
  printf("ratio = %d\n", ratio);
 }
 console_leave_raw(&con);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char c = 0;
 int ratio = 0;
 struct console_t con;
 if (argc >= 2 && !strcmp(argv[1], "-r"))
  return console_restore();
 printf("Press <j> to decrease, <k> to increase, <enter> quit\n");
 console_enter_raw(&con);
 while ( ((c = fgetc(stdin)) != (-1)) && c != '\n') {
  switch (c) {
  case 'j': dec_ratio(&ratio); break;
  case 'k': inc_ratio(&ratio); break;
  default: break;
  }
  printf("ratio = %d\n", ratio);
 }
 console_leave_raw(&con);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c char

variable_types: ratio int

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


decompiled_code:
int __fastcall parse_event(char *a1, unsigned __int16 a2, unsigned __int16 a3)
{
char *v3; // rcx
char **v4; // rax
char *v5; // rdx

v3 = (char *)&unk_402004;
v4 = names[a2];
if ( v4 )
{
v3 = v4[a3];
if ( !v3 )
v3 = (char *)&unk_402004;
}
v5 = (&events)[a2];
if ( !v5 )
v5 = (char *)&unk_402004;
return sprintf(a1, "%s.%s", v5, v3);
}

canonical_decompiled_code:
int __fastcall func7(char *a1, unsigned __int16 a2, unsigned __int16 a3)
{
char *v3; // rcx
char **v4; // rax
char *v5; // rdx

v3 = (char *)&unk_402004;
v4 = names[a2];
if ( v4 )
{
v3 = v4[a3];
if ( !v3 )
v3 = (char *)&unk_402004;
}
v5 = (&events)[a2];
if ( !v5 )
v5 = (char *)&unk_402004;
return sprintf(a1, "%s.%s", v5, v3);
}

original_code:
static void parse_event(char *str, unsigned short type, unsigned short code)
{
 sprintf(str, "%s.%s", events[type] ? events[type] : "?",
  names[type] ? (names[type][code] ? names[type][code] : "?") : "?");
}

variable_types:
type
unsigned short

variable_types:
code
unsigned short


decompiled_code:
__int64 __fastcall loop_mask_32(int a1)
{
int v1; // edi
int v2; // ecx
__int64 result; // rax
int v4; // edx

if ( a1 < 0 )
return 0LL;
v1 = a1 + 1;
v2 = 0;
LODWORD(result) = 0;
do
{
v4 = 1 << v2++;
result = v4 | (unsigned int)result;
}
while ( v1 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
int v1; // edi
int v2; // ecx
__int64 result; // rax
int v4; // edx

if ( a1 < 0 )
return 0LL;
v1 = a1 + 1;
v2 = 0;
LODWORD(result) = 0;
do
{
v4 = 1 << v2++;
result = v4 | (unsigned int)result;
}
while ( v1 != v2 );
return result;
}

original_code:
static uint32_t loop_mask_32(int n)
{
 uint32_t val = 0;
 int i = 0;
 for (i = 0; i <= n; i++)
  val |= (1 << i);
 return val;
}

canonical_original_code:
static unsigned int loop_mask_32(int n)
{
 unsigned int val = 0;
 int i = 0;
 for (i = 0; i <= n; i++)
  val |= (1 << i);
 return val;
}

variable_types:
val
unsigned int

return_type: unsigned int