repo: ryuslash/libdispass

decompiled_code:
char *__fastcall sha512_to_string(unsigned __int8 *a1, char *a2)
{
unsigned __int8 *v2; // rbx
char *result; // rax
char s[2]; // [rsp+Dh] [rbp-2Bh] BYREF
char v5; // [rsp+Fh] [rbp-29h]

v2 = a1;
do
{
*(_WORD *)s = 0;
v5 = 0;
sprintf(s, "%02x", *v2);
result = strcat(a2, s);
++v2;
}
while ( v2 != a1 + 64 );
return result;
}

canonical_decompiled_code:
char *__fastcall func6(unsigned __int8 *a1, char *a2)
{
unsigned __int8 *v2; // rbx
char *result; // rax
char s[2]; // [rsp+Dh] [rbp-2Bh] BYREF
char v5; // [rsp+Fh] [rbp-29h]

v2 = a1;
do
{
*(_WORD *)s = 0;
v5 = 0;
sprintf(s, "%02x", *v2);
result = strcat(a2, s);
++v2;
}
while ( v2 != a1 + 64 );
return result;
}

original_code:
static void
sha512_to_string(unsigned char *data, char *buff)
{
    int i;
    for (i = 0; i < 64; i++) {
        char sbuff[3] = { '\0' };
        sprintf(sbuff, "%02x", data[i]);
        strcat(buff, sbuff);
    }
}

variable_types:
data
unsigned char *

variable_types:
buff
char *

variable_types: i int

variable_types:
sbuff
char [3]


original_code:
char *
dispass1(char *label, char *password, int len, long long unsigned seqno)
{
    unsigned char *d;
    size_t tbufflen = strlen(label) + strlen(password) + 1;
    char *tbuff = calloc(tbufflen, sizeof(char));
    char buff[(64 * 2) + 1] = { '\0' };
    char *b64;
    strcat(tbuff, label);
    strcat(tbuff, password);
    d = SHA512((unsigned char *)tbuff, strlen(tbuff), 0);
    free(tbuff);
    sha512_to_string(d, buff);
    b64 = base64encode(buff, strlen(buff));
    b64[((len) < ((64 * 2)) ? (len) : ((64 * 2)))] = '\0';
    rmchar('=', &b64);
    return b64;
}

canonical_original_code:
char *dispass1(char *label, char *password, int len, unsigned long long seqno)
{
    unsigned char *d;
    unsigned long tbufflen = strlen(label) + strlen(password) + 1;
    char *tbuff = calloc(tbufflen, sizeof(char));
    char buff[-1] = { '\0' };
    char *b64;
    strcat(tbuff, label);
    strcat(tbuff, password);
    d = SHA512((unsigned char *)tbuff, strlen(tbuff), 0);
    free(tbuff);
    sha512_to_string(d, buff);
    b64 = base64encode(buff, strlen(buff));
    b64[((len) < ((64 * 2)) ? (len) : ((64 * 2)))] = '\0';
    rmchar('=', &b64);
    return b64;
}

variable_types:
label
char *

variable_types:
password
char *

variable_types: len int

variable_types:
seqno
unsigned long long

variable_types:
d
unsigned char *

variable_types:
tbufflen
unsigned long

variable_types:
tbuff
char *

variable_types:
buff
char [-1]

return_type: char *


original_code:
char *
dispass2(char *label, char *password, int len, long long unsigned seqno)
{
    unsigned char *d;
    char ibuff[300];
    char *tbuff, *b64;
    char buff[(64 * 2) + 1] = { '\0' };
    sprintf(ibuff, "%llu", seqno);
    tbuff = calloc(strlen(label) + strlen(ibuff) + strlen(password) + 1,
                   sizeof(char));
    strcat(tbuff, label);
    strcat(tbuff, ibuff);
    strcat(tbuff, password);
    d = SHA512((unsigned char *)tbuff, strlen(tbuff), 0);
    free(tbuff);
    sha512_to_string(d, buff);
    b64 = base64encode(buff, strlen(buff));
    b64[((len) < ((64 * 2)) ? (len) : ((64 * 2)))] = '\0';
    rmchar('=', &b64);
    return b64;
}

canonical_original_code:
char *dispass2(char *label, char *password, int len, unsigned long long seqno)
{
    unsigned char *d;
    char ibuff[300];
    char *tbuff; char *b64;
    char buff[-1] = { '\0' };
    sprintf(ibuff, "%llu", seqno);
    tbuff = calloc(strlen(label) + strlen(ibuff) + strlen(password) + 1,
                   sizeof(char));
    strcat(tbuff, label);
    strcat(tbuff, ibuff);
    strcat(tbuff, password);
    d = SHA512((unsigned char *)tbuff, strlen(tbuff), 0);
    free(tbuff);
    sha512_to_string(d, buff);
    b64 = base64encode(buff, strlen(buff));
    b64[((len) < ((64 * 2)) ? (len) : ((64 * 2)))] = '\0';
    rmchar('=', &b64);
    return b64;
}

variable_types:
ibuff
char [300]


repo: rzalamena/algorithm

original_code: __attribute__((__unused__)) static struct number * NHEAD_MERGE(struct number *s, struct number *e) { struct number head; struct number *a = &head; while ((s != ((void *)0)) && (e != ((void *)0))) { if ((number_cmp)(s, e) < 0) { a->n_entry.sle_next = s; a = s; s = s->n_entry.sle_next; } else { a->n_entry.sle_next = e; a = e; e = e->n_entry.sle_next; } } a->n_entry.sle_next = (s != ((void *)0)) ? (s) : (e); return (head.n_entry.sle_next); }

canonical_original_code: static struct number *NHEAD_MERGE(struct number *s, struct number *e) { struct number head; struct number *a = &head; while ((s != ((void *)0)) && (e != ((void *)0))) { if ((number_cmp)(s, e) < 0) { a->n_entry.sle_next = s; a = s; s = s->n_entry.sle_next; } else { a->n_entry.sle_next = e; a = e; e = e->n_entry.sle_next; } } a->n_entry.sle_next = (s != ((void *)0)) ? (s) : (e); return (head.n_entry.sle_next); }

variable_types:
s
struct number *

variable_types:
e
struct number *

variable_types: struct number { int n_number; struct { struct number *sle_next; } n_entry; } *


decompiled_code:
__int64 __fastcall NHEAD_MERGESORT(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // rax
__int64 v5; // rdi
_QWORD *v6; // rbp
_QWORD *v7; // rax

v1 = a1;
if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
if ( !v2 )
return a1;
v3 = a1;
do
{
v4 = *(_QWORD *)(v2 + 8);
if ( !v4 )
break;
v3 = *(_QWORD *)(v3 + 8);
v2 = *(_QWORD *)(v4 + 8);
}
while ( v2 );
v5 = *(_QWORD *)(v3 + 8);
*(_QWORD *)(v3 + 8) = 0LL;
v6 = (_QWORD *)NHEAD_MERGESORT(v5);
v7 = (_QWORD *)NHEAD_MERGESORT(v1);
return NHEAD_MERGE(v7, v6);
}

original_code: __attribute__((__unused__)) static struct number * NHEAD_MERGESORT(struct number *a) { struct number *s, *e; if ((a == ((void *)0)) || (a->n_entry.sle_next == ((void *)0))) return (a); s = a; e = a->n_entry.sle_next; while ((e != ((void *)0)) && (e->n_entry.sle_next != ((void *)0))) { a = a->n_entry.sle_next; e = e->n_entry.sle_next->n_entry.sle_next; } e = a->n_entry.sle_next; a->n_entry.sle_next = ((void *)0); return (NHEAD_MERGE(NHEAD_MERGESORT(s), NHEAD_MERGESORT(e))); }

canonical_original_code: static struct number *NHEAD_MERGESORT(struct number *a) { struct number *s; struct number *e; if ((a == ((void *)0)) || (a->n_entry.sle_next == ((void *)0))) return (a); s = a; e = a->n_entry.sle_next; while ((e != ((void *)0)) && (e->n_entry.sle_next != ((void *)0))) { a = a->n_entry.sle_next; e = e->n_entry.sle_next->n_entry.sle_next; } e = a->n_entry.sle_next; a->n_entry.sle_next = ((void *)0); return (NHEAD_MERGE(NHEAD_MERGESORT(s), NHEAD_MERGESORT(e))); }

variable_types:
a
struct number *

return_type: struct number { int n_number; struct { struct number *sle_next; } n_entry; } *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
_QWORD *v4; // rax
unsigned int *v5; // rbx
unsigned int *v6; // rbx

v3 = 1;
while ( 1 )
{
v4 = calloc(1uLL, 0x10uLL);
if ( !v4 )
break;
*(_DWORD *)v4 = v3;
v4[1] = nhead;
nhead = (__int64)v4;
if ( ++v3 == 500 )
{
puts("List:");
v5 = (unsigned int *)nhead;
if ( nhead )
{
do
{
printf(" %d", *v5);
v5 = (unsigned int *)*((_QWORD *)v5 + 1);
}
while ( v5 );
}
putchar(10);
nhead = NHEAD_MERGESORT(nhead);
puts("List sorted:");
v6 = (unsigned int *)nhead;
if ( nhead )
{
do
{
printf(" %d", *v6);
v6 = (unsigned int *)*((_QWORD *)v6 + 1);
}
while ( v6 );
}
putchar(10);
exit(0);
}
}
err(1, "calloc");
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
_QWORD *v4; // rax
unsigned int *v5; // rbx
unsigned int *v6; // rbx

v3 = 1;
while ( 1 )
{
v4 = calloc(1uLL, 0x10uLL);
if ( !v4 )
break;
*(_DWORD *)v4 = v3;
v4[1] = nhead;
nhead = (__int64)v4;
if ( ++v3 == 500 )
{
puts("List:");
v5 = (unsigned int *)nhead;
if ( nhead )
{
do
{
printf(" %d", *v5);
v5 = (unsigned int *)*((_QWORD *)v5 + 1);
}
while ( v5 );
}
putchar(10);
nhead = func9(nhead);
puts("List sorted:");
v6 = (unsigned int *)nhead;
if ( nhead )
{
do
{
printf(" %d", *v6);
v6 = (unsigned int *)*((_QWORD *)v6 + 1);
}
while ( v6 );
}
putchar(10);
exit(0);
}
}
err(1, "calloc");
}

original_code:
int
main(int argc, char *argv[])
{
 struct number *n;
 int i;
 for (i = 1; i < 500; i++) {
  n = calloc(1, sizeof(*n));
  if (n == ((void *)0))
   err(1, "calloc");
  n->n_number = i;
  do { (n)->n_entry.sle_next = (&nhead)->slh_first; (&nhead)->slh_first = (n); } while (0);
 }
 printf("List:\n");
 for((n) = ((&nhead)->slh_first); (n) != ((void *)0); (n) = ((n)->n_entry.sle_next))
  printf(" %d", n->n_number);
 printf("\n");
 ((&nhead)->slh_first = NHEAD_MERGESORT((&nhead)->slh_first));
 printf("List sorted:\n");
 for((n) = ((&nhead)->slh_first); (n) != ((void *)0); (n) = ((n)->n_entry.sle_next))
  printf(" %d", n->n_number);
 printf("\n");
 exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int

user_defined_types: struct number { int n_number; struct { struct number *sle_next; } n_entry; }


repo: rzalamena/icmp-tunnel

original_code:
static void
constroi_header_link(struct sock_ctx *ctx)
{
 ctx->saddr.sll_family = 17;
 ctx->saddr.sll_protocol = htons(0x0003);
 ctx->saddr.sll_ifindex = ctx->ifindex;
 ctx->saddr_len = sizeof(struct sockaddr_ll);
}

variable_types: struct sock_ctx { int proxy; int seq_atual; int sd; unsigned int sbuff[8192]; unsigned int *spos; unsigned int pbuff[8192]; unsigned int *ppos; unsigned int *plen; unsigned int *icmp_cksum; struct ckfields { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } ip6_src; struct in6_addr ip6_dst; unsigned int pkt_len; unsigned int dummy[3]; unsigned int nxthdr; struct icmp6_hdr { unsigned char icmp6_type; unsigned char icmp6_code; unsigned short icmp6_cksum; union { unsigned int icmp6_un_data32[1]; unsigned short icmp6_un_data16[2]; unsigned char icmp6_un_data8[4]; } icmp6_dataun; } icmp6; struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; } tcp; unsigned char msg[512]; } ckf; unsigned int mfrom[6]; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; } ifrom; unsigned int tcp_port; struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; } saddr; unsigned int saddr_len; int ifindex; char ifname[16]; } *

return_type: void

user_defined_types: struct sock_ctx { int proxy; int seq_atual; int sd; unsigned int sbuff[8192]; unsigned int *spos; unsigned int pbuff[8192]; unsigned int *ppos; unsigned int *plen; unsigned int *icmp_cksum; struct ckfields ckf; unsigned int mfrom[6]; struct sockaddr_in6 ifrom; unsigned int tcp_port; struct sockaddr_ll saddr; unsigned int saddr_len; int ifindex; char ifname[16]; }

user_defined_types: struct ckfields { struct in6_addr ip6_src; struct in6_addr ip6_dst; unsigned int pkt_len; unsigned int dummy[3]; unsigned int nxthdr; struct icmp6_hdr icmp6; struct tcphdr tcp; unsigned char msg[512]; }


original_code:
static void
constroi_header(struct sock_ctx *ctx)
{
 struct ether_header *eth;
 struct ip6_hdr *ip6;
 struct icmp6_hdr *icmp6;
 eth = (struct ether_header *) ctx->pbuff;
 memcpy(eth->ether_dhost, ctx->mto, 6);
 memcpy(eth->ether_shost, ctx->mfrom, 6);
 eth->ether_type = htons(0x86dd);
 ctx->ppos = ctx->pbuff + sizeof(struct ether_header);
 ip6 = (struct ip6_hdr *) ctx->ppos;
 ip6->ip6_ctlun.ip6_un1.ip6_un1_flow = htonl(0);
 ctx->plen = &ip6->ip6_ctlun.ip6_un1.ip6_un1_plen;
 ip6->ip6_ctlun.ip6_un1.ip6_un1_plen = htons(64);
 ip6->ip6_ctlun.ip6_un1.ip6_un1_nxt = 0x3a;
 ip6->ip6_ctlun.ip6_un1.ip6_un1_hlim = 64;
 memcpy(&ip6->ip6_src, &ctx->ifrom.sin6_addr, sizeof(struct in6_addr));
 memcpy(&ip6->ip6_dst, &ctx->ito.sin6_addr, sizeof(struct in6_addr));
 ctx->ppos += sizeof(struct ip6_hdr);
 icmp6 = (struct icmp6_hdr *) ctx->ppos;
 if (ctx->proxy)
  icmp6->icmp6_type = 129;
 else
  icmp6->icmp6_type = 128;
 icmp6->icmp6_code = 0;
 ctx->icmp_cksum = &icmp6->icmp6_cksum;
 icmp6->icmp6_dataun.icmp6_un_data16[1] = htons(ctx->seq_atual++);
 icmp6->icmp6_dataun.icmp6_un_data16[0] = htons(42);
 ctx->ppos += sizeof(struct icmp6_hdr);
 memcpy(&ctx->ckf.ip6_src, &ip6->ip6_src, sizeof(struct in6_addr));
 memcpy(&ctx->ckf.ip6_dst, &ip6->ip6_dst, sizeof(struct in6_addr));
 ctx->ckf.nxthdr = 0x3a;
 memcpy(&ctx->ckf.icmp6, (ctx->ppos - sizeof(struct icmp6_hdr)),
     sizeof(struct icmp6_hdr));
}

variable_types: struct ether_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; } *

variable_types: struct ip6_hdr { union { struct ip6_hdrctl { unsigned int ip6_un1_flow; unsigned short ip6_un1_plen; unsigned char ip6_un1_nxt; unsigned char ip6_un1_hlim; } ip6_un1; unsigned char ip6_un2_vfc; } ip6_ctlun; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } ip6_src; struct in6_addr ip6_dst; } *

variable_types: struct icmp6_hdr { unsigned char icmp6_type; unsigned char icmp6_code; unsigned short icmp6_cksum; union { unsigned int icmp6_un_data32[1]; unsigned short icmp6_un_data16[2]; unsigned char icmp6_un_data8[4]; } icmp6_dataun; } *

user_defined_types: struct ip6_hdr { union { struct ip6_hdrctl ip6_un1; unsigned char ip6_un2_vfc; } ip6_ctlun; struct in6_addr ip6_src; struct in6_addr ip6_dst; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }

user_defined_types: struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; }


original_code:
static void
constroi_header_tcp(struct sock_ctx *ctx)
{
 struct tcphdr *tcp;
 tcp = (struct tcphdr *) ctx->ppos;
 tcp->source = htons(ctx->tcp_port);
 tcp->dest = htons(ctx->tcp_port);
 tcp->seq = htonl(ctx->seq_atual);
 tcp->ack_seq = htonl(ctx->seq_atual);
 tcp->doff = 0;
 tcp->fin = 0;
 tcp->syn = 1;
 tcp->rst = 0;
 tcp->psh = 0;
 tcp->ack = 1;
 tcp->urg = 0;
 tcp->window = htons(0);
 tcp->check = htons(0);
 tcp->urg_ptr = htons(0);
 ctx->ppos += sizeof(struct tcphdr);
 memcpy(&ctx->ckf.tcp, (ctx->ppos - sizeof(struct tcphdr)),
     sizeof(struct tcphdr));
}

variable_types: struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; } *

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }

user_defined_types: struct icmp6_hdr { unsigned char icmp6_type; unsigned char icmp6_code; unsigned short icmp6_cksum; union { unsigned int icmp6_un_data32[1]; unsigned short icmp6_un_data16[2]; unsigned char icmp6_un_data8[4]; } icmp6_dataun; }


usage

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"%1$s <-c> -i interface\n"
"-s XX:XX:XX:XX:XX:XX -d XX:XX:XX:XX:XX:XX\n"
"-o IP6_ADDRESS -w IP6_ADDRESS -p PORTA\n"
"========\n"
"\t-i - Interface para onde deve se enviar o pacote. (OBRIGATORIO)\n"
"\t-w - Endereco de origem. (OBRIGATORIO)\n"
"\t-o - Endereco de destino. (OBRIGATORIO)\n"
"\t-s - MAC da interface de origem. (OBRIGATORIO)\n"
"\t-d - MAC da interface de destino. (OBRIGATORIO)\n"
"\t-c - Programa ira rodar como proxy (default cliente).\n"
"\t-p - Porta do TCP (default 8050).\n",
(const char *)_progname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func5()
{
fprintf(
stderr,
"%1$s <-c> -i interface\n"
"-s XX:XX:XX:XX:XX:XX -d XX:XX:XX:XX:XX:XX\n"
"-o IP6_ADDRESS -w IP6_ADDRESS -p PORTA\n"
"========\n"
"\t-i - Interface para onde deve se enviar o pacote. (OBRIGATORIO)\n"
"\t-w - Endereco de origem. (OBRIGATORIO)\n"
"\t-o - Endereco de destino. (OBRIGATORIO)\n"
"\t-s - MAC da interface de origem. (OBRIGATORIO)\n"
"\t-d - MAC da interface de destino. (OBRIGATORIO)\n"
"\t-c - Programa ira rodar como proxy (default cliente).\n"
"\t-p - Porta do TCP (default 8050).\n",
(const char *)_progname);
exit(1);
}

original_code:
static void
usage(void)
{
 fprintf(stderr, "%1$s <-c> -i interface\n"
     "-s XX:XX:XX:XX:XX:XX -d XX:XX:XX:XX:XX:XX\n"
     "-o IP6_ADDRESS -w IP6_ADDRESS -p PORTA\n"
     "========\n"
     "\t-i - Interface para onde deve se enviar o pacote. (OBRIGATORIO)\n"
        "\t-w - Endereco de origem. (OBRIGATORIO)\n"
     "\t-o - Endereco de destino. (OBRIGATORIO)\n"
     "\t-s - MAC da interface de origem. (OBRIGATORIO)\n"
     "\t-d - MAC da interface de destino. (OBRIGATORIO)\n"
     "\t-c - Programa ira rodar como proxy (default cliente).\n"
     "\t-p - Porta do TCP (default 8050).\n",
     __progname);
 exit(1);
}

canonical_original_code:
static void usage()
{
 fprintf(stderr, "%1$s <-c> -i interface\n"
     "-s XX:XX:XX:XX:XX:XX -d XX:XX:XX:XX:XX:XX\n"
     "-o IP6_ADDRESS -w IP6_ADDRESS -p PORTA\n"
     "========\n"
     "\t-i - Interface para onde deve se enviar o pacote. (OBRIGATORIO)\n"
        "\t-w - Endereco de origem. (OBRIGATORIO)\n"
     "\t-o - Endereco de destino. (OBRIGATORIO)\n"
     "\t-s - MAC da interface de origem. (OBRIGATORIO)\n"
     "\t-d - MAC da interface de destino. (OBRIGATORIO)\n"
     "\t-c - Programa ira rodar como proxy (default cliente).\n"
     "\t-p - Porta do TCP (default 8050).\n",
     __progname);
 exit(1);
}


original_code:
static int
mac_str2bin(const char *mac, u_int8_t mac_bin[6])
{
 if (sscanf(mac, "%02x:%02x:%02x:%02x:%02x:%02x",
     (u_int *) &mac_bin[0], (u_int *) &mac_bin[1],
     (u_int *) &mac_bin[2], (u_int *) &mac_bin[3],
     (u_int *) &mac_bin[4], (u_int *) &mac_bin[5])
     == 6)
  return(0);
 return(-1);
}

canonical_original_code:
static int mac_str2bin(char *mac, unsigned int mac_bin[6])
{
 if (sscanf(mac, "%02x:%02x:%02x:%02x:%02x:%02x",
     (unsigned int *) &mac_bin[0], (unsigned int *) &mac_bin[1],
     (unsigned int *) &mac_bin[2], (unsigned int *) &mac_bin[3],
     (unsigned int *) &mac_bin[4], (unsigned int *) &mac_bin[5])
     == 6)
  return(0);
 return(-1);
}

variable_types:
mac
char *


decompiled_code:
int __fastcall associa_interface(__int64 a1)
{
int v1; // eax
int v2; // ebp
char v4[48]; // [rsp+0h] [rbp-78h] BYREF
char dest[8]; // [rsp+30h] [rbp-48h] BYREF
__int64 v6; // [rsp+38h] [rbp-40h]
__int64 v7; // [rsp+40h] [rbp-38h]
__int64 v8; // [rsp+48h] [rbp-30h]
__int64 v9; // [rsp+50h] [rbp-28h]

v1 = socket(2, 2, 0);
if ( v1 == -1 )
err(1, "%s", "associa_interface");
v2 = v1;
*(_QWORD *)dest = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
strcpy(dest, (const char *)(a1 + 17112));
if ( ioctl(v2, 0x8933uLL, dest) == -1 )
err(1, "%s", "associa_interface");
*(_DWORD *)(a1 + 17108) = v7;
if ( !inet_ntop(10, (const void *)(a1 + 17032), v4, 0x2Eu) )
err(1, "%s", "associa_interface");
return fprintf(
stderr,
"(%s:%d) DEBUG: [interface=%s][IP=%s]\n",
"associa_interface",
33LL,
(const char *)(a1 + 17112),
v4);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
int v1; // eax
int v2; // ebp
char v4[48]; // [rsp+0h] [rbp-78h] BYREF
char dest[8]; // [rsp+30h] [rbp-48h] BYREF
__int64 v6; // [rsp+38h] [rbp-40h]
__int64 v7; // [rsp+40h] [rbp-38h]
__int64 v8; // [rsp+48h] [rbp-30h]
__int64 v9; // [rsp+50h] [rbp-28h]

v1 = socket(2, 2, 0);
if ( v1 == -1 )
err(1, "%s", "associa_interface");
v2 = v1;
*(_QWORD *)dest = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
strcpy(dest, (const char *)(a1 + 17112));
if ( ioctl(v2, 0x8933uLL, dest) == -1 )
err(1, "%s", "associa_interface");
*(_DWORD *)(a1 + 17108) = v7;
if ( !inet_ntop(10, (const void *)(a1 + 17032), v4, 0x2Eu) )
err(1, "%s", "associa_interface");
return fprintf(
stderr,
"(%s:%d) DEBUG: [interface=%s][IP=%s]\n",
"associa_interface",
33LL,
(const char *)(a1 + 17112),
v4);
}

original_code:
static void
associa_interface(struct sock_ctx *ctx)
{
 int sys_sock;
 struct ifreq ifr;
 char buf[46];
 sys_sock = socket(2, SOCK_DGRAM, 0);
 if (sys_sock == -1)
  err(1, "%s", __FUNCTION__);
 memset(&ifr, 0, sizeof(struct ifreq));
 strcpy(ifr.ifr_ifrn.ifrn_name, ctx->ifname);
 if (ioctl(sys_sock, 0x8933, &ifr) == -1)
  err(1, "%s", __FUNCTION__);
 ctx->ifindex = ifr.ifr_ifru.ifru_ivalue;
 if (inet_ntop(10, &ctx->ifrom.sin6_addr,
     buf, 46) == ((void *)0))
  err(1, "%s", __FUNCTION__);
 do { if (1) fprintf(stderr, "(%s:%d) " "DEBUG: [interface=%s][IP=%s]" "\n", __FUNCTION__, 33, ctx->ifname, buf); } while (0);;
 return;
}

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

variable_types:
buf
char [46]

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


decompiled_code:
int __fastcall inicializa_socket(_DWORD *a1)
{
unsigned __int16 v1; // ax
int result; // eax

memset(a1, 0, 0x42E8uLL);
v1 = _bswap_16(3);
result = socket(17, 3, v1);
a1[2] = result;
if ( result == -1 )
err(1, "%s", "inicializa_socket");
return result;
}

canonical_decompiled_code:
int __fastcall func8(_DWORD *a1)
{
unsigned __int16 v1; // ax
int result; // eax

memset(a1, 0, 0x42E8uLL);
v1 = func0(3);
result = socket(17, 3, v1);
a1[2] = result;
if ( result == -1 )
err(1, "%s", "inicializa_socket");
return result;
}

original_code:
void
inicializa_socket(struct sock_ctx *ctx)
{
 memset(ctx, 0, sizeof(struct sock_ctx));
 ctx->sd = socket(17, SOCK_RAW, htons(0x0003));
 if (ctx->sd == -1)
  err(1, "%s", __FUNCTION__);
}


original_code:
void
constroi_mensagem(struct sock_ctx *ctx, u_int8_t *mensagem, u_int32_t total)
{
 constroi_header(ctx);
 constroi_header_tcp(ctx);
 memcpy(ctx->ppos, mensagem, total);
 memcpy(ctx->ckf.msg, mensagem, total);
 *ctx->plen = htons(sizeof(struct icmp6_hdr) +
     sizeof(struct tcphdr) + total);
 ctx->ckf.pkt_len = htonl(ntohs(*ctx->plen));
 ctx->ppos += total;
 *ctx->icmp_cksum =
     (in_cksum((u_int16_t *) &ctx->ckf, sizeof(ctx->ckf)));
}

canonical_original_code:
void constroi_mensagem(struct sock_ctx *ctx, unsigned int *mensagem, unsigned int total)
{
 constroi_header(ctx);
 constroi_header_tcp(ctx);
 memcpy(ctx->ppos, mensagem, total);
 memcpy(ctx->ckf.msg, mensagem, total);
 *ctx->plen = htons(sizeof(struct icmp6_hdr) +
     sizeof(struct tcphdr) + total);
 ctx->ckf.pkt_len = htonl(ntohs(*ctx->plen));
 ctx->ppos += total;
 *ctx->icmp_cksum =
     (in_cksum((unsigned int *) &ctx->ckf, sizeof(ctx->ckf)));
}

variable_types:
mensagem
unsigned int *

variable_types:
total
unsigned int


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

constroi_header_link(a1);
fprintf(stderr, "(%s:%d) [PACKET_LEN=%lu]\n", "manda_mensagem", 235LL, *(_QWORD *)(a1 + 16408) - (a1 + 8216));
result = sendto(
*(_DWORD *)(a1 + 8),
(const void *)(a1 + 8216),
*(_QWORD *)(a1 + 16408) - (a1 + 8216),
0,
(const struct sockaddr *)(a1 + 17084),
*(_DWORD *)(a1 + 17104));
if ( result == -1 )
err(1, "%s", "manda_mensagem");
return result;
}

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

func1(a1);
fprintf(stderr, "(%s:%d) [PACKET_LEN=%lu]\n", "manda_mensagem", 235LL, *(_QWORD *)(a1 + 16408) - (a1 + 8216));
result = sendto(
*(_DWORD *)(a1 + 8),
(const void *)(a1 + 8216),
*(_QWORD *)(a1 + 16408) - (a1 + 8216),
0,
(const struct sockaddr *)(a1 + 17084),
*(_DWORD *)(a1 + 17104));
if ( result == -1 )
err(1, "%s", "manda_mensagem");
return result;
}

original_code:
void
manda_mensagem(struct sock_ctx *ctx)
{
 constroi_header_link(ctx);
 do { if (1) fprintf(stderr, "(%s:%d) " "[PACKET_LEN=%lu]" "\n", __FUNCTION__, 235, (ctx->ppos - ctx->pbuff)); } while (0);;
 if (sendto(ctx->sd, ctx->pbuff, (ctx->ppos - ctx->pbuff), 0,
     (struct sockaddr *) &ctx->saddr, ctx->saddr_len) == -1)
  err(1, "%s", __FUNCTION__);
}

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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
int v4; // er14
int v5; // er13
int v6; // er12
int v7; // eax
char *v8; // r12
size_t v9; // rax
int v10; // edi
int v11; // eax
__int64 v12; // rcx
struct sockaddr *v13; // rdi
unsigned int v14; // ebx
const char *v15; // rax
int result; // eax
int v17; // [rsp+Ch] [rbp-45ECh]
socklen_t addr_len; // [rsp+1Ch] [rbp-45DCh] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-45D8h] BYREF
struct timeval timeout; // [rsp+40h] [rbp-45B8h] BYREF
fd_set readfds; // [rsp+50h] [rbp-45A8h] BYREF
char v22[512]; // [rsp+D0h] [rbp-4528h] BYREF
__int64 s[2149]; // [rsp+2D0h] [rbp-4328h] BYREF

_progname = (__int64)*argv;
memset(s, 0, 0x42E8uLL);
if ( argc != 1 )
{
inicializa_socket(s);
v17 = 0;
v3 = 0;
v4 = 0;
v5 = 0;
v6 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "w:o:i:cs:d:");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'c':
LODWORD(s[0]) = 1;
break;
case 'd':
if ( (unsigned int)mac_str2bin((__int64)optarg, (__int64)&s[2127] + 2) == -1 )
{
fprintf(stderr, "Endereco de mac %s invalido.\n", optarg);
exit(1);
}
v3 = 1;
break;
case 'i':
v8 = optarg;
v9 = strlen(optarg);
memcpy(&s[2139], v8, v9);
v6 = 1;
break;
case 'o':
inet_pton(10, optarg, (char *)&s[2132] + 4);
v5 = 1;
break;
case 's':
if ( (unsigned int)mac_str2bin((__int64)optarg, (__int64)&s[2126] + 4) == -1 )
{
fprintf(stderr, "Endereco de mac %s invalido.\n", optarg);
exit(1);
}
v17 = 1;
break;
case 'w':
inet_pton(10, optarg, &s[2129]);
v4 = 1;
break;
default:
usage();
return result;
}
}
if ( !v6 || !v5 || v3 == 0 || v4 == 0 || !v17 )
usage();
associa_interface((__int64)s);
if ( LODWORD(s[0]) )
{
run_proxy(s);
exit(0);
}
strcpy(v22, "TESTE PERGUNTA?");
constroi_mensagem((__int64)s, v22, 0x10u);
manda_mensagem((__int64)s);
while ( 1 )
{
timeout.tv_usec = 0LL;
timeout.tv_sec = 15LL;
memset(&readfds, 0, sizeof(readfds));
v10 = s[1];
readfds.fds_bits[SLODWORD(s[1]) / 64] |= 1LL << (SLODWORD(s[1]) % 64);
v11 = select(v10 + 1, &readfds, 0LL, 0LL, &timeout);
if ( v11 < 0 )
break;
if ( !v11 )
{
fprintf(stderr, "ERRO: nao consegui receber nada em %d segundos.\n", 15LL);
exit(1);
}
addr_len = 28;
v12 = 7LL;
v13 = &addr;
while ( v12 )
{
*(_DWORD *)&v13->sa_family = 0;
v13 = (struct sockaddr *)((char *)v13 + 4);
--v12;
}
v14 = recvfrom(s[1], (char *)&s[1] + 4, 0x2000uLL, 0, &addr, &addr_len);
fprintf(stderr, "(%s:%d) [leu=%d]\n", "main", 366LL, v14);
if ( v14 == -1 )
err(1, "%s", "main");
if ( !v14 )
{
fwrite("ERRO: nao consegui ler nada do socket.\n", 1uLL, 0x27uLL, stderr);
exit(0);
}
v15 = (const char *)le_mensagem(s, (char *)&s[1] + 4, v14);
s[1026] = (__int64)v15;
if ( v15 )
{
fprintf(stderr, "(%s:%d) [mensagem=%s]\n", "main", 380LL, v15);
exit(0);
}
fprintf(stderr, "(%s:%d) [DESCARTANDO PACOTE DESCONHECIDO]\n", "main", 377LL);
}
err(1, "%s", "main");
}
usage();
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
int v4; // er14
int v5; // er13
int v6; // er12
int v7; // eax
char *v8; // r12
size_t v9; // rax
int v10; // edi
int v11; // eax
__int64 v12; // rcx
struct sockaddr *v13; // rdi
unsigned int v14; // ebx
const char *v15; // rax
int result; // eax
int v17; // [rsp+Ch] [rbp-45ECh]
socklen_t addr_len; // [rsp+1Ch] [rbp-45DCh] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-45D8h] BYREF
struct timeval timeout; // [rsp+40h] [rbp-45B8h] BYREF
fd_set readfds; // [rsp+50h] [rbp-45A8h] BYREF
char v22[512]; // [rsp+D0h] [rbp-4528h] BYREF
__int64 s[2149]; // [rsp+2D0h] [rbp-4328h] BYREF

_progname = (__int64)*argv;
memset(s, 0, 0x42E8uLL);
if ( argc != 1 )
{
func8(s);
v17 = 0;
v3 = 0;
v4 = 0;
v5 = 0;
v6 = 0;
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "w:o:i:cs:d:");
if ( v7 == -1 )
break;
switch ( v7 )
{
case 'c':
LODWORD(s[0]) = 1;
break;
case 'd':
if ( (unsigned int)func6((__int64)optarg, (__int64)&s[2127] + 2) == -1 )
{
fprintf(stderr, "Endereco de mac %s invalido.\n", optarg);
exit(1);
}
v3 = 1;
break;
case 'i':
v8 = optarg;
v9 = strlen(optarg);
memcpy(&s[2139], v8, v9);
v6 = 1;
break;
case 'o':
inet_pton(10, optarg, (char *)&s[2132] + 4);
v5 = 1;
break;
case 's':
if ( (unsigned int)func6((__int64)optarg, (__int64)&s[2126] + 4) == -1 )
{
fprintf(stderr, "Endereco de mac %s invalido.\n", optarg);
exit(1);
}
v17 = 1;
break;
case 'w':
inet_pton(10, optarg, &s[2129]);
v4 = 1;
break;
default:
func5();
return result;
}
}
if ( !v6 || !v5 || v3 == 0 || v4 == 0 || !v17 )
func5();
func7((__int64)s);
if ( LODWORD(s[0]) )
{
run_proxy(s);
exit(0);
}
strcpy(v22, "TESTE PERGUNTA?");
func9((__int64)s, v22, 0x10u);
func10((__int64)s);
while ( 1 )
{
timeout.tv_usec = 0LL;
timeout.tv_sec = 15LL;
memset(&readfds, 0, sizeof(readfds));
v10 = s[1];
readfds.fds_bits[SLODWORD(s[1]) / 64] |= 1LL << (SLODWORD(s[1]) % 64);
v11 = select(v10 + 1, &readfds, 0LL, 0LL, &timeout);
if ( v11 < 0 )
break;
if ( !v11 )
{
fprintf(stderr, "ERRO: nao consegui receber nada em %d segundos.\n", 15LL);
exit(1);
}
addr_len = 28;
v12 = 7LL;
v13 = &addr;
while ( v12 )
{
*(_DWORD *)&v13->sa_family = 0;
v13 = (struct sockaddr *)((char *)v13 + 4);
--v12;
}
v14 = recvfrom(s[1], (char *)&s[1] + 4, 0x2000uLL, 0, &addr, &addr_len);
fprintf(stderr, "(%s:%d) [leu=%d]\n", "main", 366LL, v14);
if ( v14 == -1 )
err(1, "%s", "main");
if ( !v14 )
{
fwrite("ERRO: nao consegui ler nada do socket.\n", 1uLL, 0x27uLL, stderr);
exit(0);
}
v15 = (const char *)le_mensagem(s, (char *)&s[1] + 4, v14);
s[1026] = (__int64)v15;
if ( v15 )
{
fprintf(stderr, "(%s:%d) [mensagem=%s]\n", "main", 380LL, v15);
exit(0);
}
fprintf(stderr, "(%s:%d) [DESCARTANDO PACOTE DESCONHECIDO]\n", "main", 377LL);
}
err(1, "%s", "main");
}
func5();
return result;
}

original_code:
int
main(int argc, char **argv)
{
 struct sock_ctx ctx;
 int opt, if_set, ip_set, ip2_set;
 int mac_set, mac2_set;
 char mensagem[512];
 int len;
 fd_set read;
 int nfds, bread;
 struct timeval timer;
 struct sockaddr_in6 recfrom;
 socklen_t ifrom_len;
 __progname = argv[0];
 memset(&ctx, 0, sizeof(ctx));
 if (argc == 1)
  usage();
 inicializa_socket(&ctx);
 if_set = ip_set = ip2_set = 0;
 mac_set = mac2_set = 0;
 while ((opt = getopt(argc, argv, "w:o:i:cs:d:")) != -1) {
  switch (opt) {
  case 'c':
   ctx.proxy = 1;
   break;
  case 's':
   if (mac_str2bin(optarg, ctx.mfrom) == -1) {
    fprintf(stderr, "Endereco de mac %s invalido.\n", optarg);
    exit(1);
   }
   mac2_set = 1;
   break;
  case 'd':
   if (mac_str2bin(optarg, ctx.mto) == -1) {
    fprintf(stderr, "Endereco de mac %s invalido.\n", optarg);
    exit(1);
   }
   mac_set = 1;
   break;
  case 'i':
   memcpy(ctx.ifname, optarg, strlen(optarg));
   if_set = 1;
   break;
  case 'o':
   ip_set = 1;
   inet_pton(10, optarg, &ctx.ito.sin6_addr);
   break;
  case 'w':
   ip2_set = 1;
   inet_pton(10, optarg, &ctx.ifrom.sin6_addr);
   break;
  default:
   usage();
  }
 }
 if (if_set == 0 || ip_set == 0 || ip2_set == 0
     || mac_set == 0 || mac2_set == 0)
  usage();
 associa_interface(&ctx);
 if (ctx.proxy) {
  run_proxy(&ctx);
  exit(0);
 }
 len = sprintf(mensagem, "TESTE PERGUNTA?");
 constroi_mensagem(&ctx, (u_int8_t *) mensagem, len + 1);
 manda_mensagem(&ctx);
retry_get:
 memset(&timer, 0, sizeof(struct timeval));
 timer.tv_sec = 15;
 timer.tv_usec = 0;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&read)->__fds_bits)[((ctx.sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ctx.sd) % (8 * (int) sizeof (__fd_mask)))))));
 nfds = select((ctx.sd + 1), &read, ((void *)0), ((void *)0), &timer);
 if (nfds < 0)
  err(1, "%s", __FUNCTION__);
 else if (nfds == 0) {
  fprintf(stderr, "ERRO: nao consegui receber nada em %d segundos.\n",
      15);
  exit(1);
 }
 ifrom_len = sizeof(struct sockaddr_in6);
 memset(&recfrom, 0, sizeof(struct sockaddr_in6));
 bread = recvfrom(ctx.sd, ctx.sbuff, 8192, 0,
     (struct sockaddr *) &recfrom, &ifrom_len);
 do { if (1) fprintf(stderr, "(%s:%d) " "[leu=%d]" "\n", __FUNCTION__, 366, bread); } while (0);;
 if (bread == -1)
  err(1, "%s", __FUNCTION__);
 else if (bread == 0) {
  fprintf(stderr, "ERRO: nao consegui ler nada do socket.\n");
  exit(0);
 }
 ctx.spos = le_mensagem(&ctx, ctx.sbuff, bread);
 if (ctx.spos == ((void *)0)) {
  do { if (1) fprintf(stderr, "(%s:%d) " "[DESCARTANDO PACOTE DESCONHECIDO]" "\n", __FUNCTION__, 377); } while (0);;
  goto retry_get;
 }
 do { if (1) fprintf(stderr, "(%s:%d) " "[mensagem=%s]" "\n", __FUNCTION__, 380, ctx.spos); } while (0);;
 exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct sock_ctx ctx;
 int opt; int if_set; int ip_set; int ip2_set;
 int mac_set; int mac2_set;
 char mensagem[512];
 int len;
 struct fd_set read;
 int nfds; int bread;
 struct timeval timer;
 struct sockaddr_in6 recfrom;
 unsigned int ifrom_len;
 __progname = argv[0];
 memset(&ctx, 0, sizeof(ctx));
 if (argc == 1)
  usage();
 inicializa_socket(&ctx);
 if_set = ip_set = ip2_set = 0;
 mac_set = mac2_set = 0;
 while ((opt = getopt(argc, argv, "w:o:i:cs:d:")) != -1) {
  switch (opt) {
  case 'c':
   ctx.proxy = 1;
   break;
  case 's':
   if (mac_str2bin(optarg, ctx.mfrom) == -1) {
    fprintf(stderr, "Endereco de mac %s invalido.\n", optarg);
    exit(1);
   }
   mac2_set = 1;
   break;
  case 'd':
   if (mac_str2bin(optarg, ctx.mto) == -1) {
    fprintf(stderr, "Endereco de mac %s invalido.\n", optarg);
    exit(1);
   }
   mac_set = 1;
   break;
  case 'i':
   memcpy(ctx.ifname, optarg, strlen(optarg));
   if_set = 1;
   break;
  case 'o':
   ip_set = 1;
   inet_pton(10, optarg, &ctx.ito.sin6_addr);
   break;
  case 'w':
   ip2_set = 1;
   inet_pton(10, optarg, &ctx.ifrom.sin6_addr);
   break;
  default:
   usage();
  }
 }
 if (if_set == 0 || ip_set == 0 || ip2_set == 0
     || mac_set == 0 || mac2_set == 0)
  usage();
 associa_interface(&ctx);
 if (ctx.proxy) {
  run_proxy(&ctx);
  exit(0);
 }
 len = sprintf(mensagem, "TESTE PERGUNTA?");
 constroi_mensagem(&ctx, (unsigned int *) mensagem, len + 1);
 manda_mensagem(&ctx);
retry_get:
 memset(&timer, 0, sizeof(struct timeval));
 timer.tv_sec = 15;
 timer.tv_usec = 0;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&read)->__fds_bits)[((ctx.sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ctx.sd) % (8 * (int) sizeof (__fd_mask)))))));
 nfds = select((ctx.sd + 1), &read, ((void *)0), ((void *)0), &timer);
 if (nfds < 0)
  err(1, "%s", __FUNCTION__);
 else if (nfds == 0) {
  fprintf(stderr, "ERRO: nao consegui receber nada em %d segundos.\n",
      15);
  exit(1);
 }
 ifrom_len = sizeof(struct sockaddr_in6);
 memset(&recfrom, 0, sizeof(struct sockaddr_in6));
 bread = recvfrom(ctx.sd, ctx.sbuff, 8192, 0,
     (struct sockaddr *) &recfrom, &ifrom_len);
 do { if (1) fprintf(stderr, "(%s:%d) " "[leu=%d]" "\n", __FUNCTION__, 366, bread); } while (0);;
 if (bread == -1)
  err(1, "%s", __FUNCTION__);
 else if (bread == 0) {
  fprintf(stderr, "ERRO: nao consegui ler nada do socket.\n");
  exit(0);
 }
 ctx.spos = le_mensagem(&ctx, ctx.sbuff, bread);
 if (ctx.spos == ((void *)0)) {
  do { if (1) fprintf(stderr, "(%s:%d) " "[DESCARTANDO PACOTE DESCONHECIDO]" "\n", __FUNCTION__, 377); } while (0);;
  goto retry_get;
 }
 do { if (1) fprintf(stderr, "(%s:%d) " "[mensagem=%s]" "\n", __FUNCTION__, 380, ctx.spos); } while (0);;
 exit(0);
}

variable_types:
argv
char **

variable_types: struct sock_ctx { int proxy; int seq_atual; int sd; unsigned int sbuff[8192]; unsigned int *spos; unsigned int pbuff[8192]; unsigned int *ppos; unsigned int *plen; unsigned int *icmp_cksum; struct ckfields { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } ip6_src; struct in6_addr ip6_dst; unsigned int pkt_len; unsigned int dummy[3]; unsigned int nxthdr; struct icmp6_hdr { unsigned char icmp6_type; unsigned char icmp6_code; unsigned short icmp6_cksum; union { unsigned int icmp6_un_data32[1]; unsigned short icmp6_un_data16[2]; unsigned char icmp6_un_data8[4]; } icmp6_dataun; } icmp6; struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; } tcp; unsigned char msg[512]; } ckf; unsigned int mfrom[6]; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; } ifrom; unsigned int tcp_port; struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; } saddr; unsigned int saddr_len; int ifindex; char ifname[16]; }

variable_types: opt int

variable_types:
mensagem
char [512]

variable_types: len int

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

variable_types: nfds int

variable_types: bread int

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

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; }


original_code:
static void
responde_mensagem(struct sock_ctx *ctx)
{
 struct ether_header *eth;
 struct ip6_hdr *ip6;
 struct icmp6_hdr *icmp6;
 struct tcphdr *tcp;
 char mensagem[512];
 int mlen;
 eth = (struct ether_header *) ctx->pbuff;
 memcpy(eth->ether_dhost, ctx->mto, 6);
 memcpy(eth->ether_shost, ctx->mfrom, 6);
 eth->ether_type = htons(0x86dd);
 ctx->ppos = ctx->pbuff + sizeof(struct ether_header);
 ip6 = (struct ip6_hdr *) ctx->ppos;
 ip6->ip6_ctlun.ip6_un1.ip6_un1_flow = htonl(0);
 ctx->plen = &ip6->ip6_ctlun.ip6_un1.ip6_un1_plen;
 ip6->ip6_ctlun.ip6_un1.ip6_un1_plen = htons(64);
 ip6->ip6_ctlun.ip6_un1.ip6_un1_nxt = 0x3a;
 ip6->ip6_ctlun.ip6_un1.ip6_un1_hlim = 64;
 memcpy(&ip6->ip6_src, &ctx->ifrom.sin6_addr, sizeof(struct in6_addr));
 memcpy(&ip6->ip6_dst, &ctx->ito.sin6_addr, sizeof(struct in6_addr));
 ctx->ppos += sizeof(struct ip6_hdr);
 icmp6 = (struct icmp6_hdr *) ctx->ppos;
 if (ctx->proxy)
  icmp6->icmp6_type = 129;
 else
  icmp6->icmp6_type = 128;
 icmp6->icmp6_code = 0;
 ctx->icmp_cksum = &icmp6->icmp6_cksum;
 icmp6->icmp6_dataun.icmp6_un_data16[1] = htons(++ctx->seq_atual);
 icmp6->icmp6_dataun.icmp6_un_data16[0] = htons(42);
 ctx->ppos += sizeof(struct icmp6_hdr);
 tcp = (struct tcphdr *) ctx->ppos;
 tcp->source = htons(ctx->tcp_port);
 tcp->dest = htons(ctx->tcp_port);
 tcp->seq = htonl(ctx->seq_atual);
 tcp->ack_seq = htonl(ctx->seq_atual);
 tcp->doff = 0;
 tcp->fin = 0;
 tcp->syn = 1;
 tcp->rst = 0;
 tcp->psh = 0;
 tcp->ack = 1;
 tcp->urg = 0;
 tcp->window = htons(0);
 tcp->check = htons(0);
 tcp->urg_ptr = htons(0);
 ctx->ppos += sizeof(struct tcphdr);
 memcpy(&ctx->ckf.tcp, (ctx->ppos - sizeof(struct tcphdr)),
     sizeof(struct tcphdr));
 memcpy(&ctx->ckf.ip6_src, &ip6->ip6_src, sizeof(struct in6_addr));
 memcpy(&ctx->ckf.ip6_dst, &ip6->ip6_dst, sizeof(struct in6_addr));
 ctx->ckf.nxthdr = 0x3a;
 memcpy(&ctx->ckf.icmp6, (ctx->ppos - sizeof(struct icmp6_hdr)),
     sizeof(struct icmp6_hdr));
 mlen = sprintf(mensagem, "TESTE RESPOSTA");
 constroi_mensagem(ctx, (u_int8_t *) mensagem, mlen + 1);
 manda_mensagem(ctx);
}

canonical_original_code:
static void responde_mensagem(struct sock_ctx *ctx)
{
 struct ether_header *eth;
 struct ip6_hdr *ip6;
 struct icmp6_hdr *icmp6;
 struct tcphdr *tcp;
 char mensagem[512];
 int mlen;
 eth = (struct ether_header *) ctx->pbuff;
 memcpy(eth->ether_dhost, ctx->mto, 6);
 memcpy(eth->ether_shost, ctx->mfrom, 6);
 eth->ether_type = htons(0x86dd);
 ctx->ppos = ctx->pbuff + sizeof(struct ether_header);
 ip6 = (struct ip6_hdr *) ctx->ppos;
 ip6->ip6_ctlun.ip6_un1.ip6_un1_flow = htonl(0);
 ctx->plen = &ip6->ip6_ctlun.ip6_un1.ip6_un1_plen;
 ip6->ip6_ctlun.ip6_un1.ip6_un1_plen = htons(64);
 ip6->ip6_ctlun.ip6_un1.ip6_un1_nxt = 0x3a;
 ip6->ip6_ctlun.ip6_un1.ip6_un1_hlim = 64;
 memcpy(&ip6->ip6_src, &ctx->ifrom.sin6_addr, sizeof(struct in6_addr));
 memcpy(&ip6->ip6_dst, &ctx->ito.sin6_addr, sizeof(struct in6_addr));
 ctx->ppos += sizeof(struct ip6_hdr);
 icmp6 = (struct icmp6_hdr *) ctx->ppos;
 if (ctx->proxy)
  icmp6->icmp6_type = 129;
 else
  icmp6->icmp6_type = 128;
 icmp6->icmp6_code = 0;
 ctx->icmp_cksum = &icmp6->icmp6_cksum;
 icmp6->icmp6_dataun.icmp6_un_data16[1] = htons(++ctx->seq_atual);
 icmp6->icmp6_dataun.icmp6_un_data16[0] = htons(42);
 ctx->ppos += sizeof(struct icmp6_hdr);
 tcp = (struct tcphdr *) ctx->ppos;
 tcp->source = htons(ctx->tcp_port);
 tcp->dest = htons(ctx->tcp_port);
 tcp->seq = htonl(ctx->seq_atual);
 tcp->ack_seq = htonl(ctx->seq_atual);
 tcp->doff = 0;
 tcp->fin = 0;
 tcp->syn = 1;
 tcp->rst = 0;
 tcp->psh = 0;
 tcp->ack = 1;
 tcp->urg = 0;
 tcp->window = htons(0);
 tcp->check = htons(0);
 tcp->urg_ptr = htons(0);
 ctx->ppos += sizeof(struct tcphdr);
 memcpy(&ctx->ckf.tcp, (ctx->ppos - sizeof(struct tcphdr)),
     sizeof(struct tcphdr));
 memcpy(&ctx->ckf.ip6_src, &ip6->ip6_src, sizeof(struct in6_addr));
 memcpy(&ctx->ckf.ip6_dst, &ip6->ip6_dst, sizeof(struct in6_addr));
 ctx->ckf.nxthdr = 0x3a;
 memcpy(&ctx->ckf.icmp6, (ctx->ppos - sizeof(struct icmp6_hdr)),
     sizeof(struct icmp6_hdr));
 mlen = sprintf(mensagem, "TESTE RESPOSTA");
 constroi_mensagem(ctx, (unsigned int *) mensagem, mlen + 1);
 manda_mensagem(ctx);
}

variable_types: struct sock_ctx { int proxy; int seq_atual; int sd; unsigned int sbuff[8192]; unsigned int *spos; unsigned int pbuff[8192]; unsigned int *ppos; unsigned int *plen; unsigned int *icmp_cksum; struct ckfields { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } ip6_src; struct in6_addr ip6_dst; unsigned int pkt_len; unsigned int dummy[3]; unsigned int nxthdr; struct icmp6_hdr { unsigned char icmp6_type; unsigned char icmp6_code; unsigned short icmp6_cksum; union { unsigned int icmp6_un_data32[1]; unsigned short icmp6_un_data16[2]; unsigned char icmp6_un_data8[4]; } icmp6_dataun; } icmp6; struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; } tcp; unsigned char msg[512]; } ckf; unsigned int mfrom[6]; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; } ifrom; unsigned int tcp_port; struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; } saddr; unsigned int saddr_len; int ifindex; char ifname[16]; } *

variable_types: struct ether_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; } *

variable_types: struct ip6_hdr { union { struct ip6_hdrctl { unsigned int ip6_un1_flow; unsigned short ip6_un1_plen; unsigned char ip6_un1_nxt; unsigned char ip6_un1_hlim; } ip6_un1; unsigned char ip6_un2_vfc; } ip6_ctlun; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } ip6_src; struct in6_addr ip6_dst; } *

variable_types: struct icmp6_hdr { unsigned char icmp6_type; unsigned char icmp6_code; unsigned short icmp6_cksum; union { unsigned int icmp6_un_data32[1]; unsigned short icmp6_un_data16[2]; unsigned char icmp6_un_data8[4]; } icmp6_dataun; } *

variable_types: mlen int


decompiled_code:
__int64 __fastcall run_proxy(__int64 a1)
{
int v2; // edi
int v3; // eax
unsigned int v4; // ebp
const char *v5; // rax
struct sockaddr v7; // [rsp+0h] [rbp-C8h] BYREF
__int64 v8; // [rsp+10h] [rbp-B8h]
int v9; // [rsp+18h] [rbp-B0h]
socklen_t addr_len; // [rsp+1Ch] [rbp-ACh] BYREF
struct timeval timeout; // [rsp+20h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-98h] BYREF

while ( 1 )
{
timeout.tv_usec = 0LL;
timeout.tv_sec = 15LL;
memset(&readfds, 0, sizeof(readfds));
v2 = *(_DWORD *)(a1 + 8);
readfds.fds_bits[v2 / 64] |= 1LL << (v2 % 64);
v3 = select(v2 + 1, &readfds, 0LL, 0LL, &timeout);
if ( v3 < 0 )
err(1, "%s", "run_proxy");
if ( !v3 )
{
fprintf(stderr, "ERRO: nao consegui receber nada em %d segundos.\n", 15LL);
exit(1);
}
addr_len = 28;
*(_QWORD *)&v7.sa_family = 0LL;
*(_QWORD *)&v7.sa_data[6] = 0LL;
v8 = 0LL;
v9 = 0;
v4 = recvfrom(*(_DWORD *)(a1 + 8), (void *)(a1 + 12), 0x2000uLL, 0, &v7, &addr_len);
fprintf(stderr, "(%s:%d) [leu=%d]\n", "run_proxy", 256LL, v4);
if ( v4 == -1 )
err(1, "%s", "run_proxy");
if ( !v4 )
{
fwrite("ERRO: nao consegui ler nada do socket.\n", 1uLL, 0x27uLL, stderr);
exit(0);
}
v5 = (const char *)le_mensagem((_DWORD *)a1, a1 + 12, v4);
*(_QWORD *)(a1 + 8208) = v5;
if ( v5 )
break;
fprintf(stderr, "(%s:%d) [DESCARTANDO PACOTE DESCONHECIDO]\n", "run_proxy", 267LL);
}
fprintf(stderr, "(%s:%d) [mensagem=%s]\n", "run_proxy", 270LL, v5);
fprintf(stderr, "(%s:%d) [RESPONDENDO_MENSAGEM_PERGUNTA]\n", "run_proxy", 272LL);
return responde_mensagem(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v2; // edi
int v3; // eax
unsigned int v4; // ebp
const char *v5; // rax
struct sockaddr v7; // [rsp+0h] [rbp-C8h] BYREF
__int64 v8; // [rsp+10h] [rbp-B8h]
int v9; // [rsp+18h] [rbp-B0h]
socklen_t addr_len; // [rsp+1Ch] [rbp-ACh] BYREF
struct timeval timeout; // [rsp+20h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-98h] BYREF

while ( 1 )
{
timeout.tv_usec = 0LL;
timeout.tv_sec = 15LL;
memset(&readfds, 0, sizeof(readfds));
v2 = *(_DWORD *)(a1 + 8);
readfds.fds_bits[v2 / 64] |= 1LL << (v2 % 64);
v3 = select(v2 + 1, &readfds, 0LL, 0LL, &timeout);
if ( v3 < 0 )
err(1, "%s", "run_proxy");
if ( !v3 )
{
fprintf(stderr, "ERRO: nao consegui receber nada em %d segundos.\n", 15LL);
exit(1);
}
addr_len = 28;
*(_QWORD *)&v7.sa_family = 0LL;
*(_QWORD *)&v7.sa_data[6] = 0LL;
v8 = 0LL;
v9 = 0;
v4 = recvfrom(*(_DWORD *)(a1 + 8), (void *)(a1 + 12), 0x2000uLL, 0, &v7, &addr_len);
fprintf(stderr, "(%s:%d) [leu=%d]\n", "run_proxy", 256LL, v4);
if ( v4 == -1 )
err(1, "%s", "run_proxy");
if ( !v4 )
{
fwrite("ERRO: nao consegui ler nada do socket.\n", 1uLL, 0x27uLL, stderr);
exit(0);
}
v5 = (const char *)func3((_DWORD *)a1, a1 + 12, v4);
*(_QWORD *)(a1 + 8208) = v5;
if ( v5 )
break;
fprintf(stderr, "(%s:%d) [DESCARTANDO PACOTE DESCONHECIDO]\n", "run_proxy", 267LL);
}
fprintf(stderr, "(%s:%d) [mensagem=%s]\n", "run_proxy", 270LL, v5);
fprintf(stderr, "(%s:%d) [RESPONDENDO_MENSAGEM_PERGUNTA]\n", "run_proxy", 272LL);
return func2(a1);
}

original_code:
void
run_proxy(struct sock_ctx *ctx)
{
 fd_set read;
 int nfds, bread;
 struct timeval timer;
 socklen_t ifrom_len;
 struct sockaddr_in6 source;
retry_get:
 memset(&timer, 0, sizeof(struct timeval));
 timer.tv_sec = 15;
 timer.tv_usec = 0;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&read)->__fds_bits)[((ctx->sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ctx->sd) % (8 * (int) sizeof (__fd_mask)))))));
 nfds = select((ctx->sd + 1), &read, ((void *)0), ((void *)0), &timer);
 if (nfds < 0)
  err(1, "%s", __FUNCTION__);
 else if (nfds == 0) {
  fprintf(stderr, "ERRO: nao consegui receber nada em %d segundos.\n",
      15);
  exit(1);
 }
 ifrom_len = sizeof(struct sockaddr_in6);
 memset(&source, 0, sizeof(struct sockaddr_in6));
 bread = recvfrom(ctx->sd, ctx->sbuff, 8192, 0,
     (struct sockaddr *) &source, &ifrom_len);
 do { if (1) fprintf(stderr, "(%s:%d) " "[leu=%d]" "\n", __FUNCTION__, 256, bread); } while (0);;
 if (bread == -1)
  err(1, "%s", __FUNCTION__);
 else if (bread == 0) {
  fprintf(stderr, "ERRO: nao consegui ler nada do socket.\n");
  exit(0);
 }
 ctx->spos = le_mensagem(ctx, ctx->sbuff, bread);
 if (ctx->spos == ((void *)0)) {
  do { if (1) fprintf(stderr, "(%s:%d) " "[DESCARTANDO PACOTE DESCONHECIDO]" "\n", __FUNCTION__, 267); } while (0);;
  goto retry_get;
 }
 do { if (1) fprintf(stderr, "(%s:%d) " "[mensagem=%s]" "\n", __FUNCTION__, 270, ctx->spos); } while (0);;
 do { if (1) fprintf(stderr, "(%s:%d) " "[RESPONDENDO_MENSAGEM_PERGUNTA]" "\n", __FUNCTION__, 272); } while (0);;
 responde_mensagem(ctx);
}

canonical_original_code:
void run_proxy(struct sock_ctx *ctx)
{
 struct fd_set read;
 int nfds; int bread;
 struct timeval timer;
 unsigned int ifrom_len;
 struct sockaddr_in6 source;
retry_get:
 memset(&timer, 0, sizeof(struct timeval));
 timer.tv_sec = 15;
 timer.tv_usec = 0;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&read)->__fds_bits)[((ctx->sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ctx->sd) % (8 * (int) sizeof (__fd_mask)))))));
 nfds = select((ctx->sd + 1), &read, ((void *)0), ((void *)0), &timer);
 if (nfds < 0)
  err(1, "%s", __FUNCTION__);
 else if (nfds == 0) {
  fprintf(stderr, "ERRO: nao consegui receber nada em %d segundos.\n",
      15);
  exit(1);
 }
 ifrom_len = sizeof(struct sockaddr_in6);
 memset(&source, 0, sizeof(struct sockaddr_in6));
 bread = recvfrom(ctx->sd, ctx->sbuff, 8192, 0,
     (struct sockaddr *) &source, &ifrom_len);
 do { if (1) fprintf(stderr, "(%s:%d) " "[leu=%d]" "\n", __FUNCTION__, 256, bread); } while (0);;
 if (bread == -1)
  err(1, "%s", __FUNCTION__);
 else if (bread == 0) {
  fprintf(stderr, "ERRO: nao consegui ler nada do socket.\n");
  exit(0);
 }
 ctx->spos = le_mensagem(ctx, ctx->sbuff, bread);
 if (ctx->spos == ((void *)0)) {
  do { if (1) fprintf(stderr, "(%s:%d) " "[DESCARTANDO PACOTE DESCONHECIDO]" "\n", __FUNCTION__, 267); } while (0);;
  goto retry_get;
 }
 do { if (1) fprintf(stderr, "(%s:%d) " "[mensagem=%s]" "\n", __FUNCTION__, 270, ctx->spos); } while (0);;
 do { if (1) fprintf(stderr, "(%s:%d) " "[RESPONDENDO_MENSAGEM_PERGUNTA]" "\n", __FUNCTION__, 272); } while (0);;
 responde_mensagem(ctx);
}

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


original_code:
unsigned short in_cksum(unsigned short *addr,int len)
{
        register int sum = 0;
        u_short answer = 0;
        register u_short *w = addr;
        register int nleft = len;
        while (nleft > 1) {
                sum += *w++;
                nleft -= 2;
        }
        if (nleft == 1) {
                *(u_char *)(&answer) = *(u_char *)w ;
                sum += answer;
        }
        sum = (sum >> 16) + (sum & 0xffff);
        sum += (sum >> 16);
        answer = ~sum;
        return(answer);
}

canonical_original_code:
unsigned short in_cksum(unsigned short *addr, int len)
{
        register int sum = 0;
        unsigned short answer = 0;
        register unsigned short *w = addr;
        register int nleft = len;
        while (nleft > 1) {
                sum += *w++;
                nleft -= 2;
        }
        if (nleft == 1) {
                *(unsigned char *)(&answer) = *(unsigned char *)w ;
                sum += answer;
        }
        sum = (sum >> 16) + (sum & 0xffff);
        sum += (sum >> 16);
        answer = ~sum;
        return(answer);
}

variable_types:
addr
unsigned short *

variable_types: sum int

variable_types:
answer
unsigned short

variable_types:
w
unsigned short *

variable_types: nleft int

return_type: unsigned short


repo: s-ltf/IMS

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

v1.sa_handler = (__sighandler_t)(_bswap_16 + 1);
v1.sa_flags = 0;
sigemptyset(&v1.sa_mask);
return sigaction(13, &v1, 0LL);
}

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

v1.sa_handler = (__sighandler_t)(_bswap_16 + 1);
v1.sa_flags = 0;
sigemptyset(&v1.sa_mask);
return sigaction(13, &v1, 0LL);
}

original_code:
void ignore_pipe(void)
{
  struct sigaction sig;
  sig.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
  sig.sa_flags = 0;
  sigemptyset(&sig.sa_mask);
  sigaction(13,&sig,((void *)0));
}

canonical_original_code:
void ignore_pipe()
{
  struct sigaction sig;
  sig.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
  sig.sa_flags = 0;
  sigemptyset(&sig.sa_mask);
  sigaction(13,&sig,((void *)0));
}

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

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

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


PrintPhonemes

repo: s-macke/SAM

original_code:
void PrintPhonemes(unsigned char *phonemeindex, unsigned char *phonemeLength, unsigned char *stress)
{
    int i = 0;
    printf("===========================================\n");
    printf("Internal Phoneme presentation:\n\n");
    printf(" idx    phoneme  length  stress\n");
    printf("------------------------------\n");
    while((phonemeindex[i] != 255) && (i < 255))
    {
        if (phonemeindex[i] < 81)
        {
            printf(" %3i      %c%c      %3i       %i\n",
            phonemeindex[i],
            signInputTable1[phonemeindex[i]],
            signInputTable2[phonemeindex[i]],
            phonemeLength[i],
            stress[i]
            );
        } else
        {
            printf(" %3i      ??      %3i       %i\n", phonemeindex[i], phonemeLength[i], stress[i]);
        }
        i++;
    }
    printf("===========================================\n");
    printf("\n");
}

variable_types:
phonemeindex
unsigned char *

variable_types:
phonemeLength
unsigned char *

variable_types:
stress
unsigned char *

variable_types: i int


PrintOutput

variable_types:
flag
unsigned char *

variable_types:
p
unsigned char *


PrintRule

decompiled_code:
int __fastcall PrintRule(unsigned __int16 a1)
{
unsigned __int8 v1; // bp
char v2; // al
char v3; // bl

printf("Applying rule: ");
v1 = 1;
do
{
v2 = GetRuleByte(a1, v1);
v3 = v2;
if ( (v2 & 0x7F) == 61 )
printf(" -> ");
else
putchar(v2 & 0x7F);
++v1;
}
while ( v3 >= 0 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(unsigned __int16 a1)
{
unsigned __int8 v1; // bp
char v2; // al
char v3; // bl

printf("Applying rule: ");
v1 = 1;
do
{
v2 = GetRuleByte(a1, v1);
v3 = v2;
if ( (v2 & 0x7F) == 61 )
printf(" -> ");
else
putchar(v2 & 0x7F);
++v1;
}
while ( v3 >= 0 );
return putchar(10);
}

original_code:
void PrintRule(int offset)
{
    int i = 1;
    unsigned char A = 0;
    printf("Applying rule: ");
    do
    {
        A = GetRuleByte(offset, i);
        if ((A&127) == '=') printf(" -> "); else printf("%c", A&127);
        i++;
    } while ((A&128)==0);
    printf("\n");
}

variable_types: offset int

variable_types:
A
unsigned char


MixAudio

decompiled_code:
unsigned __int64 __fastcall MixAudio(__int64 a1, _BYTE *a2, int a3)
{
int v4; // ebx
__int64 v5; // rcx
unsigned __int64 result; // rax
int v7; // ebx
__int64 v8; // rsi

v4 = GetBufferLength();
v5 = GetBuffer();
result = (unsigned int)pos;
if ( pos < v4 )
{
v7 = v4 - pos;
if ( v7 > a3 )
v7 = a3;
if ( v7 > 0 )
{
result = (unsigned __int64)a2;
v8 = (__int64)&a2[v7 - 1 + 1];
do
*(_BYTE *)result++ = *(_BYTE *)(v5 + pos++);
while ( result != v8 );
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, _BYTE *a2, int a3)
{
int v4; // ebx
__int64 v5; // rcx
unsigned __int64 result; // rax
int v7; // ebx
__int64 v8; // rsi

v4 = GetBufferLength();
v5 = GetBuffer();
result = (unsigned int)pos;
if ( pos < v4 )
{
v7 = v4 - pos;
if ( v7 > a3 )
v7 = a3;
if ( v7 > 0 )
{
result = (unsigned __int64)a2;
v8 = (__int64)&a2[v7 - 1 + 1];
do
*(_BYTE *)result++ = *(_BYTE *)(v5 + pos++);
while ( result != v8 );
}
}
return result;
}

original_code:
void MixAudio(void *unused, Uint8 *stream, int len)
{
    int bufferpos = GetBufferLength();
    char *buffer = GetBuffer();
    int i;
    if (pos >= bufferpos) return;
    if ((bufferpos-pos) < len) len = (bufferpos-pos);
    for(i=0; i<len; i++)
    {
        stream[i] = buffer[pos];
        pos++;
    }
}

canonical_original_code:
void MixAudio(void *unused, unsigned char *stream, int len)
{
    int bufferpos = GetBufferLength();
    char *buffer = GetBuffer();
    int i;
    if (pos >= bufferpos) return;
    if ((bufferpos-pos) < len) len = (bufferpos-pos);
    for(i=0; i<len; i++)
    {
        stream[i] = buffer[pos];
        pos++;
    }
}

variable_types:
unused
void *

variable_types:
stream
unsigned char *

variable_types: len int

variable_types: bufferpos int

variable_types:
buffer
char *


PrintUsage

decompiled_code:
int PrintUsage()
{
puts("usage: sam [options] Word1 Word2 ....");
puts("options");
puts(" -phonetic enters phonetic mode. (see below)");
puts(" -pitch number set pitch value (default=64)");
puts(" -speed number set speed value (default=72)");
puts(" -throat number set throat value (default=128)");
puts(" -mouth number set mouth value (default=128)");
puts(" -wav filename output to wav instead of libsdl");
puts(" -sing special treatment of pitch");
puts(" -debug print additional debug messages");
putchar(10);
puts(" VOWELS VOICED CONSONANTS ");
puts("IY f(ee)t R red ");
puts("IH p(i)n L allow ");
puts("EH beg W away ");
puts("AE Sam W whale ");
puts("AA pot Y you ");
puts("AH b(u)dget M Sam ");
puts("AO t(al)k N man ");
puts("OH cone NX so(ng) ");
puts("UH book B bad ");
puts("UX l(oo)t D dog ");
puts("ER bird G again ");
puts("AX gall(o)n J judge ");
puts("IX dig(i)t Z zoo ");
puts(" ZH plea(s)ure ");
puts(" DIPHTHONGS V seven ");
puts("EY m(a)de DH (th)en ");
puts("AY h(igh) ");
puts("OY boy ");
puts("AW h(ow) UNVOICED CONSONANTS ");
puts("OW slow S Sam ");
puts("UW crew Sh fish ");
puts(" F fish ");
puts(" TH thin ");
puts(" SPECIAL PHONEMES P poke ");
puts("UL sett(le) (=AXL) T talk ");
puts("UM astron(omy) (=AXM) K cake ");
puts("UN functi(on) (=AXN) CH speech ");
return puts("Q kitt-en (glottal stop) /H a(h)ead ");
}

canonical_decompiled_code:
int func2()
{
puts("usage: sam [options] Word1 Word2 ....");
puts("options");
puts(" -phonetic enters phonetic mode. (see below)");
puts(" -pitch number set pitch value (default=64)");
puts(" -speed number set speed value (default=72)");
puts(" -throat number set throat value (default=128)");
puts(" -mouth number set mouth value (default=128)");
puts(" -wav filename output to wav instead of libsdl");
puts(" -sing special treatment of pitch");
puts(" -debug print additional debug messages");
putchar(10);
puts(" VOWELS VOICED CONSONANTS ");
puts("IY f(ee)t R red ");
puts("IH p(i)n L allow ");
puts("EH beg W away ");
puts("AE Sam W whale ");
puts("AA pot Y you ");
puts("AH b(u)dget M Sam ");
puts("AO t(al)k N man ");
puts("OH cone NX so(ng) ");
puts("UH book B bad ");
puts("UX l(oo)t D dog ");
puts("ER bird G again ");
puts("AX gall(o)n J judge ");
puts("IX dig(i)t Z zoo ");
puts(" ZH plea(s)ure ");
puts(" DIPHTHONGS V seven ");
puts("EY m(a)de DH (th)en ");
puts("AY h(igh) ");
puts("OY boy ");
puts("AW h(ow) UNVOICED CONSONANTS ");
puts("OW slow S Sam ");
puts("UW crew Sh fish ");
puts(" F fish ");
puts(" TH thin ");
puts(" SPECIAL PHONEMES P poke ");
puts("UL sett(le) (=AXL) T talk ");
puts("UM astron(omy) (=AXM) K cake ");
puts("UN functi(on) (=AXN) CH speech ");
return puts("Q kitt-en (glottal stop) /H a(h)ead ");
}

original_code:
void PrintUsage()
{
    printf("usage: sam [options] Word1 Word2 ....\n");
    printf("options\n");
    printf("    -phonetic         enters phonetic mode. (see below)\n");
    printf("    -pitch number        set pitch value (default=64)\n");
    printf("    -speed number        set speed value (default=72)\n");
    printf("    -throat number        set throat value (default=128)\n");
    printf("    -mouth number        set mouth value (default=128)\n");
    printf("    -wav filename        output to wav instead of libsdl\n");
    printf("    -sing            special treatment of pitch\n");
    printf("    -debug            print additional debug messages\n");
    printf("\n");
    printf("     VOWELS                            VOICED CONSONANTS    \n");
    printf("IY           f(ee)t                    R        red        \n");
    printf("IH           p(i)n                     L        allow        \n");
    printf("EH           beg                       W        away        \n");
    printf("AE           Sam                       W        whale        \n");
    printf("AA           pot                       Y        you        \n");
    printf("AH           b(u)dget                  M        Sam        \n");
    printf("AO           t(al)k                    N        man        \n");
    printf("OH           cone                      NX       so(ng)        \n");
    printf("UH           book                      B        bad        \n");
    printf("UX           l(oo)t                    D        dog        \n");
    printf("ER           bird                      G        again        \n");
    printf("AX           gall(o)n                  J        judge        \n");
    printf("IX           dig(i)t                   Z        zoo        \n");
    printf("                       ZH       plea(s)ure    \n");
    printf("   DIPHTHONGS                          V        seven        \n");
    printf("EY           m(a)de                    DH       (th)en        \n");
    printf("AY           h(igh)                        \n");
    printf("OY           boy                        \n");
    printf("AW           h(ow)                     UNVOICED CONSONANTS    \n");
    printf("OW           slow                      S         Sam        \n");
    printf("UW           crew                      Sh        fish        \n");
    printf("                                       F         fish        \n");
    printf("                                       TH        thin        \n");
    printf(" SPECIAL PHONEMES                      P         poke        \n");
    printf("UL           sett(le) (=AXL)           T         talk        \n");
    printf("UM           astron(omy) (=AXM)        K         cake        \n");
    printf("UN           functi(on) (=AXN)         CH        speech        \n");
    printf("Q            kitt-en (glottal stop)    /H        a(h)ead    \n");
}


OutputSound

decompiled_code:
__int64 OutputSound()
{
int v0; // ebx
const char *v2; // rax
int v3; // [rsp+0h] [rbp-28h] BYREF
__int16 v4; // [rsp+4h] [rbp-24h]
char v5; // [rsp+6h] [rbp-22h]
__int16 v6; // [rsp+8h] [rbp-20h]
unsigned __int64 (__fastcall *v7)(__int64, _BYTE *, int); // [rsp+10h] [rbp-18h]
__int64 v8; // [rsp+18h] [rbp-10h]

v0 = (int)GetBufferLength() / 50;
v3 = 22050;
v4 = 8;
v5 = 1;
v6 = 2048;
v7 = MixAudio;
v8 = 0LL;
if ( (int)SDL_OpenAudio(&v3, 0LL) < 0 )
{
v2 = (const char *)SDL_GetError();
printf("Unable to open audio: %s\n", v2);
exit(1);
}
SDL_PauseAudio(0LL);
while ( pos < v0 )
SDL_Delay(100LL);
return SDL_CloseAudio();
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // ebx
const char *v2; // rax
int v3; // [rsp+0h] [rbp-28h] BYREF
__int16 v4; // [rsp+4h] [rbp-24h]
char v5; // [rsp+6h] [rbp-22h]
__int16 v6; // [rsp+8h] [rbp-20h]
unsigned __int64 (__fastcall *v7)(__int64, _BYTE *, int); // [rsp+10h] [rbp-18h]
__int64 v8; // [rsp+18h] [rbp-10h]

v0 = (int)GetBufferLength() / 50;
v3 = 22050;
v4 = 8;
v5 = 1;
v6 = 2048;
v7 = MixAudio;
v8 = 0LL;
if ( (int)SDL_OpenAudio(&v3, 0LL) < 0 )
{
v2 = (const char *)SDL_GetError();
printf("Unable to open audio: %s\n", v2);
exit(1);
}
SDL_PauseAudio(0LL);
while ( pos < v0 )
SDL_Delay(100LL);
return SDL_CloseAudio();
}

original_code:
void OutputSound()
{
    int bufferpos = GetBufferLength();
    bufferpos /= 50;
    SDL_AudioSpec fmt;
    fmt.freq = 22050;
    fmt.format = 0x0008;
    fmt.channels = 1;
    fmt.samples = 2048;
    fmt.callback = MixAudio;
    fmt.userdata = ((void *)0);
    if ( SDL_OpenAudio(&fmt, ((void *)0)) < 0 )
    {
        printf("Unable to open audio: %s\n", SDL_GetError());
        exit(1);
    }
    SDL_PauseAudio(0);
    while (pos < bufferpos)
    {
        SDL_Delay(100);
    }
    SDL_CloseAudio();
}

canonical_original_code:
void OutputSound()
{
    int bufferpos = GetBufferLength();
    bufferpos /= 50;
    struct SDL_AudioSpec fmt;
    fmt.freq = 22050;
    fmt.format = 0x0008;
    fmt.channels = 1;
    fmt.samples = 2048;
    fmt.callback = MixAudio;
    fmt.userdata = ((void *)0);
    if ( SDL_OpenAudio(&fmt, ((void *)0)) < 0 )
    {
        printf("Unable to open audio: %s\n", SDL_GetError());
        exit(1);
    }
    SDL_PauseAudio(0);
    while (pos < bufferpos)
    {
        SDL_Delay(100);
    }
    SDL_CloseAudio();
}

variable_types: struct SDL_AudioSpec { int freq; unsigned short format; unsigned char channels; unsigned char silence; unsigned short samples; unsigned short padding; unsigned int size; void (*callback)(void *userdata, unsigned char *stream, int len); void *userdata; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v5; // r12
char *v6; // rdx
char *v7; // rax
int i; // ebx
__int64 v9; // r14
const char *v10; // rsi
const char *v11; // rbp
bool v12; // al
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
const char *v17; // rsi
unsigned __int8 v18; // al
unsigned __int8 v19; // al
unsigned __int8 v20; // al
unsigned __int8 v21; // al
char v22; // di
int v23; // ebx
const void *v24; // rax
const char *v26; // rax
const char *v27; // [rsp+0h] [rbp-148h]
int v28; // [rsp+Ch] [rbp-13Ch]
char dest[2]; // [rsp+10h] [rbp-138h] BYREF
char v30[56]; // [rsp+110h] [rbp-38h] BYREF

v5 = dest;
v6 = v30;
v7 = dest;
do
*v7++ = 0;
while ( v30 != v7 );
if ( argc <= 1 )
{
LABEL_46:
PrintUsage();
return 1;
}
v27 = 0LL;
v28 = 0;
for ( i = 1; i < argc; ++i )
{
v9 = i;
v10 = argv[v9];
if ( *v10 == 45 )
{
v11 = v10 + 1;
v12 = strcmp(v10 + 1, "wav") != 0;
v13 = 0;
v14 = !v12;
if ( v12 )
{
v15 = "sing";
v16 = 5LL;
v17 = v10 + 1;
do
{
if ( !v16 )
break;
v13 = *v17 < (unsigned int)*v15;
v14 = *v17++ == *v15++;
--v16;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
{
EnableSingmode(v15, v17, v6);
}
else if ( !strcmp(v11, "phonetic") )
{
v28 = 1;
}
else if ( !strcmp(v11, "debug") )
{
debug = 1;
}
else if ( !strcmp(v11, "pitch") )
{
v19 = atoi(argv[v9 + 1]);
SetPitch(v19);
++i;
}
else if ( !strcmp(v11, "speed") )
{
v20 = atoi(argv[v9 + 1]);
SetSpeed(v20);
++i;
}
else if ( !strcmp(v11, "mouth") )
{
v21 = atoi(argv[v9 + 1]);
SetMouth(v21);
++i;
}
else
{
if ( strcmp(v11, "throat") )
goto LABEL_46;
v18 = atoi(argv[v9 + 1]);
SetThroat(v18);
++i;
}
}
else
{
v27 = argv[v9 + 1];
++i;
}
}
else
{
strncat(dest, v10, 0xFFuLL);
*(_WORD *)&dest[strlen(dest)] = 32;
}
}
v22 = dest[0];
if ( dest[0] )
{
do
{
*v5++ = toupper(v22);
v22 = *v5;
}
while ( *v5 );
}
if ( debug )
{
if ( v28 )
{
printf("phonetic input: %s\n", dest);
LABEL_39:
*(_WORD *)&dest[strlen(dest)] = 155;
goto LABEL_40;
}
printf("text input: %s\n", dest);
}
else if ( v28 )
{
goto LABEL_39;
}
*(_WORD *)&dest[strlen(dest)] = 91;
if ( !(unsigned int)TextToPhonemes(dest) )
return 1;
if ( debug )
printf("phonetic input: %s\n", dest);
LABEL_40:
if ( (int)SDL_Init(16LL) < 0 )
{
v26 = (const char *)SDL_GetError();
printf("Unable to init SDL: %s\n", v26);
exit(1);
}
atexit((void (*)(void))&SDL_Quit);
SetInput(dest);
if ( !(unsigned int)SAMMain() )
goto LABEL_46;
if ( v27 )
{
v23 = GetBufferLength();
v24 = (const void *)GetBuffer();
WriteWav(v27, v24, v23 / 50);
}
else
{
OutputSound();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v5; // r12
char *v6; // rdx
char *v7; // rax
int i; // ebx
__int64 v9; // r14
const char *v10; // rsi
const char *v11; // rbp
bool v12; // al
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
const char *v17; // rsi
unsigned __int8 v18; // al
unsigned __int8 v19; // al
unsigned __int8 v20; // al
unsigned __int8 v21; // al
char v22; // di
int v23; // ebx
const void *v24; // rax
const char *v26; // rax
const char *v27; // [rsp+0h] [rbp-148h]
int v28; // [rsp+Ch] [rbp-13Ch]
char dest[2]; // [rsp+10h] [rbp-138h] BYREF
char v30[56]; // [rsp+110h] [rbp-38h] BYREF

v5 = dest;
v6 = v30;
v7 = dest;
do
*v7++ = 0;
while ( v30 != v7 );
if ( argc <= 1 )
{
LABEL_46:
func2();
return 1;
}
v27 = 0LL;
v28 = 0;
for ( i = 1; i < argc; ++i )
{
v9 = i;
v10 = argv[v9];
if ( *v10 == 45 )
{
v11 = v10 + 1;
v12 = strcmp(v10 + 1, "wav") != 0;
v13 = 0;
v14 = !v12;
if ( v12 )
{
v15 = "sing";
v16 = 5LL;
v17 = v10 + 1;
do
{
if ( !v16 )
break;
v13 = *v17 < (unsigned int)*v15;
v14 = *v17++ == *v15++;
--v16;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
{
EnableSingmode(v15, v17, v6);
}
else if ( !strcmp(v11, "phonetic") )
{
v28 = 1;
}
else if ( !strcmp(v11, "debug") )
{
debug = 1;
}
else if ( !strcmp(v11, "pitch") )
{
v19 = atoi(argv[v9 + 1]);
SetPitch(v19);
++i;
}
else if ( !strcmp(v11, "speed") )
{
v20 = atoi(argv[v9 + 1]);
SetSpeed(v20);
++i;
}
else if ( !strcmp(v11, "mouth") )
{
v21 = atoi(argv[v9 + 1]);
SetMouth(v21);
++i;
}
else
{
if ( strcmp(v11, "throat") )
goto LABEL_46;
v18 = atoi(argv[v9 + 1]);
SetThroat(v18);
++i;
}
}
else
{
v27 = argv[v9 + 1];
++i;
}
}
else
{
strncat(dest, v10, 0xFFuLL);
*(_WORD *)&dest[strlen(dest)] = 32;
}
}
v22 = dest[0];
if ( dest[0] )
{
do
{
*v5++ = toupper(v22);
v22 = *v5;
}
while ( *v5 );
}
if ( debug )
{
if ( v28 )
{
printf("phonetic input: %s\n", dest);
LABEL_39:
*(_WORD *)&dest[strlen(dest)] = 155;
goto LABEL_40;
}
printf("text input: %s\n", dest);
}
else if ( v28 )
{
goto LABEL_39;
}
*(_WORD *)&dest[strlen(dest)] = 91;
if ( !(unsigned int)TextToPhonemes(dest) )
return 1;
if ( debug )
printf("phonetic input: %s\n", dest);
LABEL_40:
if ( (int)SDL_Init(16LL) < 0 )
{
v26 = (const char *)SDL_GetError();
printf("Unable to init SDL: %s\n", v26);
exit(1);
}
atexit((void (*)(void))&SDL_Quit);
SetInput(dest);
if ( !(unsigned int)SAMMain() )
goto LABEL_46;
if ( v27 )
{
v23 = GetBufferLength();
v24 = (const void *)GetBuffer();
func1(v27, v24, v23 / 50);
}
else
{
func3();
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
    int i;
    int phonetic = 0;
    char* wavfilename = ((void *)0);
    char input[256];
    for(i=0; i<256; i++) input[i] = 0;
    if (argc <= 1)
    {
        PrintUsage();
        return 1;
    }
    i = 1;
    while(i < argc)
    {
        if (argv[i][0] != '-')
        {
            strncat(input, argv[i], 255);
            strncat(input, " ", 255);
        } else
        {
            if (strcmp(&argv[i][1], "wav")==0)
            {
                wavfilename = argv[i+1];
                i++;
            } else
            if (strcmp(&argv[i][1], "sing")==0)
            {
                EnableSingmode();
            } else
            if (strcmp(&argv[i][1], "phonetic")==0)
            {
                phonetic = 1;
            } else
            if (strcmp(&argv[i][1], "debug")==0)
            {
                debug = 1;
            } else
            if (strcmp(&argv[i][1], "pitch")==0)
            {
                SetPitch(atoi(argv[i+1]));
                i++;
            } else
            if (strcmp(&argv[i][1], "speed")==0)
            {
                SetSpeed(atoi(argv[i+1]));
                i++;
            } else
            if (strcmp(&argv[i][1], "mouth")==0)
            {
                SetMouth(atoi(argv[i+1]));
                i++;
            } else
            if (strcmp(&argv[i][1], "throat")==0)
            {
                SetThroat(atoi(argv[i+1]));
                i++;
            } else
            {
                PrintUsage();
                return 1;
            }
        }
        i++;
    }
    for(i=0; input[i] != 0; i++)
        input[i] = toupper((int)input[i]);
    if (debug)
    {
        if (phonetic) printf("phonetic input: %s\n", input);
        else printf("text input: %s\n", input);
    }
    if (!phonetic)
    {
        strncat(input, "[", 256);
        if (!TextToPhonemes((unsigned char *)input)) return 1;
        if (debug)
            printf("phonetic input: %s\n", input);
    } else strncat(input, "\x9b", 256);
    if ( SDL_Init(0x00000010) < 0 )
    {
        printf("Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
    }
    atexit(SDL_Quit);
    SetInput(input);
    if (!SAMMain())
    {
        PrintUsage();
        return 1;
    }
    if (wavfilename != ((void *)0))
        WriteWav(wavfilename, GetBuffer(), GetBufferLength()/50);
    else
        OutputSound();
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int i;
    int phonetic = 0;
    char *wavfilename = ((void *)0);
    char input[256];
    for(i=0; i<256; i++) input[i] = 0;
    if (argc <= 1)
    {
        PrintUsage();
        return 1;
    }
    i = 1;
    while(i < argc)
    {
        if (argv[i][0] != '-')
        {
            strncat(input, argv[i], 255);
            strncat(input, " ", 255);
        } else
        {
            if (strcmp(&argv[i][1], "wav")==0)
            {
                wavfilename = argv[i+1];
                i++;
            } else
            if (strcmp(&argv[i][1], "sing")==0)
            {
                EnableSingmode();
            } else
            if (strcmp(&argv[i][1], "phonetic")==0)
            {
                phonetic = 1;
            } else
            if (strcmp(&argv[i][1], "debug")==0)
            {
                debug = 1;
            } else
            if (strcmp(&argv[i][1], "pitch")==0)
            {
                SetPitch(atoi(argv[i+1]));
                i++;
            } else
            if (strcmp(&argv[i][1], "speed")==0)
            {
                SetSpeed(atoi(argv[i+1]));
                i++;
            } else
            if (strcmp(&argv[i][1], "mouth")==0)
            {
                SetMouth(atoi(argv[i+1]));
                i++;
            } else
            if (strcmp(&argv[i][1], "throat")==0)
            {
                SetThroat(atoi(argv[i+1]));
                i++;
            } else
            {
                PrintUsage();
                return 1;
            }
        }
        i++;
    }
    for(i=0; input[i] != 0; i++)
        input[i] = toupper((int)input[i]);
    if (debug)
    {
        if (phonetic) printf("phonetic input: %s\n", input);
        else printf("text input: %s\n", input);
    }
    if (!phonetic)
    {
        strncat(input, "[", 256);
        if (!TextToPhonemes((unsigned char *)input)) return 1;
        if (debug)
            printf("phonetic input: %s\n", input);
    } else strncat(input, "\x9b", 256);
    if ( SDL_Init(0x00000010) < 0 )
    {
        printf("Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
    }
    atexit(SDL_Quit);
    SetInput(input);
    if (!SAMMain())
    {
        PrintUsage();
        return 1;
    }
    if (wavfilename != ((void *)0))
        WriteWav(wavfilename, GetBuffer(), GetBufferLength()/50);
    else
        OutputSound();
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: phonetic int

variable_types:
wavfilename
char *

variable_types:
input
char [256]


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

X = a1 - 1;
Y = inputtemp[(unsigned __int8)(a1 - 1)];
result = (unsigned __int8)tab36376[(unsigned __int8)Y];
A = tab36376[(unsigned __int8)Y];
return result;
}

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

X = a1 - 1;
Y = inputtemp[(unsigned __int8)(a1 - 1)];
result = (unsigned __int8)tab36376[(unsigned __int8)Y];
A = tab36376[(unsigned __int8)Y];
return result;
}

original_code:
void Code37055(unsigned char mem59)
{
    X = mem59;
    X--;
    A = inputtemp[X];
    Y = A;
    A = tab36376[Y];
    return;
}


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

X = a1 + 1;
Y = inputtemp[(unsigned __int8)(a1 + 1)];
result = (unsigned __int8)tab36376[(unsigned __int8)Y];
A = tab36376[(unsigned __int8)Y];
return result;
}

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

X = a1 + 1;
Y = inputtemp[(unsigned __int8)(a1 + 1)];
result = (unsigned __int8)tab36376[(unsigned __int8)Y];
A = tab36376[(unsigned __int8)Y];
return result;
}

original_code:
void Code37066(unsigned char mem58)
{
    X = mem58;
    X++;
    A = inputtemp[X];
    Y = A;
    A = tab36376[Y];
}


GetRuleByte

decompiled_code:
__int64 __fastcall GetRuleByte(unsigned __int16 a1, unsigned __int8 a2)
{
__int64 result; // rax

if ( a1 > 0x92A4u )
result = (unsigned __int8)rules2[a1 - 37541 + a2];
else
result = (unsigned __int8)rules[a1 - 32000 + a2];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 a1, unsigned __int8 a2)
{
__int64 result; // rax

if ( a1 > 0x92A4u )
result = (unsigned __int8)rules2[a1 - 37541 + a2];
else
result = (unsigned __int8)rules[a1 - 32000 + a2];
return result;
}

original_code:
unsigned char GetRuleByte(unsigned short mem62, unsigned char Y)
{
    unsigned int address = mem62;
    if (mem62 >= 37541)
    {
        address -= 37541;
        return rules2[address+Y];
    }
    address -= 32000;
    return rules[address+Y];
}

variable_types:
Y
unsigned char

variable_types:
address
unsigned int

return_type: unsigned char