original_code:
u16 mult16(u16 a, u16 b)
{
    u16 prod;
    u8 ahi4, alow4, bhi4, blow4, temp;
    u8 reshibit, hibit0, hibit1;
    prod.hi8 = 0;
    ahi4 = a.lo8 >> 32;
    alow4 = (a.lo8 & 0xFFFFFFFFLL);
    bhi4 = b.lo8 >> 32;
    blow4 = (b.lo8 & 0xFFFFFFFFLL);
    prod.lo8 = alow4 * blow4;
    temp = ahi4 * blow4;
    prod.hi8 += temp >> 32;
    temp <<= 32;
    hibit0 = (temp & 0x8000000000000000LL);
    hibit1 = (prod.lo8 & 0x8000000000000000LL);
    prod.lo8 += temp;
    reshibit = (prod.lo8 & 0x8000000000000000LL);
    if ((hibit0 & hibit1) || ((hibit0 ^ hibit1) && reshibit == 0LL))
        prod.hi8++;
    temp = alow4 * bhi4;
    prod.hi8 += temp >> 32;
    temp <<= 32;
    hibit0 = (temp & 0x8000000000000000LL);
    hibit1 = (prod.lo8 & 0x8000000000000000LL);
    prod.lo8 += temp;
    reshibit = (prod.lo8 & 0x8000000000000000LL);
    if ((hibit0 & hibit1) || ((hibit0 ^ hibit1) && reshibit == 0LL))
        prod.hi8++;
    prod.hi8 += ahi4 * bhi4;
    prod.hi8 += a.lo8 * b.hi8;
    prod.hi8 += a.hi8 * b.lo8;
    return (prod);
}

canonical_original_code:
struct u16 mult16(struct u16 a, struct u16 b)
{
    struct u16 prod;
    unsigned long long ahi4; unsigned long long alow4; unsigned long long bhi4; unsigned long long blow4; unsigned long long temp;
    unsigned long long reshibit; unsigned long long hibit0; unsigned long long hibit1;
    prod.hi8 = 0;
    ahi4 = a.lo8 >> 32;
    alow4 = (a.lo8 & 0xFFFFFFFFLL);
    bhi4 = b.lo8 >> 32;
    blow4 = (b.lo8 & 0xFFFFFFFFLL);
    prod.lo8 = alow4 * blow4;
    temp = ahi4 * blow4;
    prod.hi8 += temp >> 32;
    temp <<= 32;
    hibit0 = (temp & 0x8000000000000000LL);
    hibit1 = (prod.lo8 & 0x8000000000000000LL);
    prod.lo8 += temp;
    reshibit = (prod.lo8 & 0x8000000000000000LL);
    if ((hibit0 & hibit1) || ((hibit0 ^ hibit1) && reshibit == 0LL))
        prod.hi8++;
    temp = alow4 * bhi4;
    prod.hi8 += temp >> 32;
    temp <<= 32;
    hibit0 = (temp & 0x8000000000000000LL);
    hibit1 = (prod.lo8 & 0x8000000000000000LL);
    prod.lo8 += temp;
    reshibit = (prod.lo8 & 0x8000000000000000LL);
    if ((hibit0 & hibit1) || ((hibit0 ^ hibit1) && reshibit == 0LL))
        prod.hi8++;
    prod.hi8 += ahi4 * bhi4;
    prod.hi8 += a.lo8 * b.hi8;
    prod.hi8 += a.hi8 * b.lo8;
    return (prod);
}

variable_types:
a
struct u16

variable_types:
b
struct u16

variable_types:
reshibit
unsigned long long

return_type: struct u16 { unsigned long long hi8; unsigned long long lo8; }


canonical_original_code:
struct u16 add16(struct u16 a, struct u16 b)
{
    struct u16 sum;
    unsigned long long reshibit; unsigned long long hibit0; unsigned long long hibit1;
    sum.hi8 = a.hi8 + b.hi8;
    hibit0 = (a.lo8 & 0x8000000000000000LL);
    hibit1 = (b.lo8 & 0x8000000000000000LL);
    sum.lo8 = a.lo8 + b.lo8;
    reshibit = (sum.lo8 & 0x8000000000000000LL);
    if ((hibit0 & hibit1) || ((hibit0 ^ hibit1) && reshibit == 0LL))
        sum.hi8++;
    return (sum);
}

variable_types: struct u16 { unsigned long long hi8; unsigned long long lo8; }


decompiled_code:
__int64 __fastcall dec_to_u16(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
unsigned __int64 v3; // rdx
__int64 result; // rax
__int64 v5; // rax
__int64 v6; // rdx

v1 = *a1;
if ( (unsigned __int8)(*a1 - 48) > 9u )
return 0LL;
v2 = a1;
v3 = 0LL;
result = 0LL;
do
{
v5 = add16((v3 >> 61) + 8 * result, 8 * v3, (v3 >> 63) + 2 * result, 2 * v3);
result = add16(v5, v6, 0LL, v1 - 48);
v1 = *++v2;
}
while ( (unsigned __int8)(*v2 - 48) <= 9u );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
unsigned __int64 v3; // rdx
__int64 result; // rax
__int64 v5; // rax
__int64 v6; // rdx

v1 = *a1;
if ( (unsigned __int8)(*a1 - 48) > 9u )
return 0LL;
v2 = a1;
v3 = 0LL;
result = 0LL;
do
{
v5 = func4((v3 >> 61) + 8 * result, 8 * v3, (v3 >> 63) + 2 * result, 2 * v3);
result = func4(v5, v6, 0LL, v1 - 48);
v1 = *++v2;
}
while ( (unsigned __int8)(*v2 - 48) <= 9u );
return result;
}

original_code:
u16 dec_to_u16(const char *s)
{
    u16 result;
    u16 temp;
    const char *p;
    result.hi8 = 0;
    result.lo8 = 0;
    for (p = s; *p >= '0' && *p <= '9'; p++)
    {
        temp = result;
        result.hi8 <<= 3;
        result.hi8 += (result.lo8 & 0xE000000000000000ULL) >> 61;
        result.lo8 <<= 3;
        temp.hi8 <<= 1;
        temp.hi8 += (temp.lo8 & 0x8000000000000000ULL) >> 63;
        temp.lo8 <<= 1;
        result = add16(result, temp);
        temp.hi8 = 0;
        temp.lo8 = *p - '0';
        result = add16(result, temp);
    }
    return (result);
}

canonical_original_code:
struct u16 dec_to_u16(char *s)
{
    struct u16 result;
    struct u16 temp;
    char *p;
    result.hi8 = 0;
    result.lo8 = 0;
    for (p = s; *p >= '0' && *p <= '9'; p++)
    {
        temp = result;
        result.hi8 <<= 3;
        result.hi8 += (result.lo8 & 0xE000000000000000ULL) >> 61;
        result.lo8 <<= 3;
        temp.hi8 <<= 1;
        temp.hi8 += (temp.lo8 & 0x8000000000000000ULL) >> 63;
        temp.lo8 <<= 1;
        result = add16(result, temp);
        temp.hi8 = 0;
        temp.lo8 = *p - '0';
        result = add16(result, temp);
    }
    return (result);
}

variable_types:
s
char *

variable_types:
p
char *

user_defined_types: struct u16 { unsigned long long hi8; unsigned long long lo8; }


original_code:
u16 skip_ahead_rand(u16 advance)
{
    int i;
    u16 new;
    u8 bit_map;
    new.hi8 = 0;
    new.lo8 = 0;
    bit_map = advance.lo8;
    for (i = 0; bit_map && i < 64; i++)
    {
        if (bit_map & ((u8)1 << i))
        {
            new = add16(mult16(new, Gen[i].a), Gen[i].c);
            bit_map &= ~((u8)1 << i);
        }
    }
    bit_map = advance.hi8;
    for (i = 0; bit_map && i < 64; i++)
    {
        if (bit_map & ((u8)1 << i))
        {
            new = add16(mult16(new, Gen[i + 64].a), Gen[i + 64].c);
            bit_map &= ~((u8)1 << i);
        }
    }
    return (new);
}

canonical_original_code:
struct u16 skip_ahead_rand(struct u16 advance)
{
    int i;
    struct u16 new;
    unsigned long long bit_map;
    new.hi8 = 0;
    new.lo8 = 0;
    bit_map = advance.lo8;
    for (i = 0; bit_map && i < 64; i++)
    {
        if (bit_map & ((unsigned long long)1 << i))
        {
            new = add16(mult16(new, Gen[i].a), Gen[i].c);
            bit_map &= ~((unsigned long long)1 << i);
        }
    }
    bit_map = advance.hi8;
    for (i = 0; bit_map && i < 64; i++)
    {
        if (bit_map & ((unsigned long long)1 << i))
        {
            new = add16(mult16(new, Gen[i + 64].a), Gen[i + 64].c);
            bit_map &= ~((unsigned long long)1 << i);
        }
    }
    return (new);
}

variable_types:
advance
struct u16

variable_types: i int


original_code:
u16 next_rand(u16 rand)
{
    rand = add16(mult16(rand, Gen[0].a), Gen[0].c);
    return (rand);
}

canonical_original_code:
struct u16 next_rand(struct u16 rand)
{
    rand = add16(mult16(rand, Gen[0].a), Gen[0].c);
    return (rand);
}

variable_types:
rand
struct u16


repo: ramrunner/nbeng

decompiled_code:
struct addrinfo *__fastcall prepare_socket(__int64 a1, const char *a2, const char *a3, int a4)
{
int v6; // eax
int v7; // eax
struct addrinfo *v8; // rbp
int v9; // eax
int v10; // ebx
struct addrinfo *v11; // rbp
struct addrinfo *result; // rax
const char *v13; // rax
const char *v14; // rax
int optval; // [rsp+4h] [rbp-A4h] BYREF
struct addrinfo *v16; // [rsp+8h] [rbp-A0h] BYREF
struct addrinfo v17; // [rsp+10h] [rbp-98h] BYREF
struct addrinfo *pai; // [rsp+48h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+50h] [rbp-58h] BYREF

optval = 1;
if ( a3 == 0LL || a2 == 0LL || !a1 )
errx(1, "prepare_socket was passed a null arg");
*(_QWORD *)&req.ai_flags = 0x200000000LL;
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
*(_QWORD *)&v17.ai_socktype = 0LL;
*(_QWORD *)&v17.ai_addrlen = 0LL;
v17.ai_addr = 0LL;
v17.ai_canonname = 0LL;
v17.ai_next = 0LL;
v17.ai_family = 2;
v17.ai_flags = 1;
*(_QWORD *)&v17.ai_socktype = (unsigned int)((unsigned int)(*(_DWORD *)a1 - 2) > 1) + 1;
req.ai_socktype = v17.ai_socktype;
v6 = getaddrinfo(a2, a3, &req, &pai);
if ( v6 )
{
v13 = gai_strerror(v6);
errx(1, "getaddrinfo: %s", v13);
}
v7 = getaddrinfo(0LL, a3, &v17, &v16);
if ( v7 )
{
v14 = gai_strerror(v7);
errx(1, "getaddrinfo: %s", v14);
}
v8 = pai;
if ( !pai )
LABEL_19:
err(1, "socket");
while ( 1 )
{
v9 = socket(v8->ai_family, v8->ai_socktype, v8->ai_protocol);
v10 = v9;
if ( v9 >= 0 )
break;
LABEL_18:
v8 = v8->ai_next;
if ( !v8 )
goto LABEL_19;
}
if ( setsockopt(v9, 1, 2, &optval, 4u) < 0 )
{
close(v10);
warn("setsockopt");
goto LABEL_18;
}
v11 = v16;
if ( !v16 )
LABEL_21:
err(1, "bind");
while ( bind(v10, v11->ai_addr, v11->ai_addrlen) < 0 )
{
close(v10);
warn("bind");
v11 = v11->ai_next;
if ( !v11 )
goto LABEL_21;
}
if ( *(_DWORD *)a1 != 1 && a4 )
listen(v10, 5);
*(_DWORD *)(a1 + 4) = v10;
result = pai;
*(_QWORD *)(a1 + 4240) = pai;
return result;
}

canonical_decompiled_code:
struct addrinfo *__fastcall func0(__int64 a1, const char *a2, const char *a3, int a4)
{
int v6; // eax
int v7; // eax
struct addrinfo *v8; // rbp
int v9; // eax
int v10; // ebx
struct addrinfo *v11; // rbp
struct addrinfo *result; // rax
const char *v13; // rax
const char *v14; // rax
int optval; // [rsp+4h] [rbp-A4h] BYREF
struct addrinfo *v16; // [rsp+8h] [rbp-A0h] BYREF
struct addrinfo v17; // [rsp+10h] [rbp-98h] BYREF
struct addrinfo *pai; // [rsp+48h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+50h] [rbp-58h] BYREF

optval = 1;
if ( a3 == 0LL || a2 == 0LL || !a1 )
errx(1, "prepare_socket was passed a null arg");
*(_QWORD *)&req.ai_flags = 0x200000000LL;
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
*(_QWORD *)&v17.ai_socktype = 0LL;
*(_QWORD *)&v17.ai_addrlen = 0LL;
v17.ai_addr = 0LL;
v17.ai_canonname = 0LL;
v17.ai_next = 0LL;
v17.ai_family = 2;
v17.ai_flags = 1;
*(_QWORD *)&v17.ai_socktype = (unsigned int)((unsigned int)(*(_DWORD *)a1 - 2) > 1) + 1;
req.ai_socktype = v17.ai_socktype;
v6 = getaddrinfo(a2, a3, &req, &pai);
if ( v6 )
{
v13 = gai_strerror(v6);
errx(1, "getaddrinfo: %s", v13);
}
v7 = getaddrinfo(0LL, a3, &v17, &v16);
if ( v7 )
{
v14 = gai_strerror(v7);
errx(1, "getaddrinfo: %s", v14);
}
v8 = pai;
if ( !pai )
LABEL_19:
err(1, "socket");
while ( 1 )
{
v9 = socket(v8->ai_family, v8->ai_socktype, v8->ai_protocol);
v10 = v9;
if ( v9 >= 0 )
break;
LABEL_18:
v8 = v8->ai_next;
if ( !v8 )
goto LABEL_19;
}
if ( setsockopt(v9, 1, 2, &optval, 4u) < 0 )
{
close(v10);
warn("setsockopt");
goto LABEL_18;
}
v11 = v16;
if ( !v16 )
LABEL_21:
err(1, "bind");
while ( bind(v10, v11->ai_addr, v11->ai_addrlen) < 0 )
{
close(v10);
warn("bind");
v11 = v11->ai_next;
if ( !v11 )
goto LABEL_21;
}
if ( *(_DWORD *)a1 != 1 && a4 )
listen(v10, 5);
*(_DWORD *)(a1 + 4) = v10;
result = pai;
*(_QWORD *)(a1 + 4240) = pai;
return result;
}

original_code:
static void
prepare_socket(concontxt *con, char *host, char *port, int lflag)
{
 struct addrinfo cli_hints, *cli_servinfo, srv_hints, *srv_servinfo, *p0;
 int rv, cli_sockfd, optval = 1;
 if ((con == ((void *)0)) || (host == ((void *)0)) || (port == ((void *)0)))
  errx(1, "prepare_socket was passed a null arg");
 memset(&cli_hints, 0, sizeof (cli_hints));
 memset(&srv_hints, 0, sizeof (srv_hints));
 cli_hints.ai_family = srv_hints.ai_family = 2;
 srv_hints.ai_flags = 0x0001;
 cli_hints.ai_socktype = srv_hints.ai_socktype =
  ((con->contype == 2) || (con->contype == 3))
  ? SOCK_STREAM : SOCK_DGRAM;
 rv = getaddrinfo(host, port, &cli_hints, &cli_servinfo);
 if (rv)
  errx(1, "getaddrinfo: %s", gai_strerror(rv));
 rv = getaddrinfo(((void *)0), port, &srv_hints, &srv_servinfo);
 if (rv)
  errx(1, "getaddrinfo: %s", gai_strerror(rv));
 for (p0 = cli_servinfo; p0; p0 = p0->ai_next) {
  cli_sockfd = socket(p0->ai_family, p0->ai_socktype,
        p0->ai_protocol);
  if (cli_sockfd < 0)
   continue;
  rv = setsockopt(cli_sockfd, 1,
    2, &optval, sizeof (optval));
  if (rv < 0) {
   close(cli_sockfd);
   warn("setsockopt");
   continue;
  }
  break;
 }
 if (!p0)
  err(1, "socket");
 for (p0 = srv_servinfo; p0; p0 = p0->ai_next) {
  if (bind(cli_sockfd, p0->ai_addr, p0->ai_addrlen) < 0) {
   close(cli_sockfd);
   warn("bind");
   continue;
  }
  break;
 }
 if (!p0)
  err(1, "bind");
 if (con->contype != 1 && lflag)
  listen(cli_sockfd, 5);
 con->confd = cli_sockfd;
 con->clinfo = cli_servinfo;
}

canonical_original_code:
static void prepare_socket(struct concontxt_t *con, char *host, char *port, int lflag)
{
 struct addrinfo cli_hints; struct addrinfo *cli_servinfo; struct addrinfo srv_hints; struct addrinfo *srv_servinfo; struct addrinfo *p0;
 int rv; int cli_sockfd; int optval = 1;
 if ((con == ((void *)0)) || (host == ((void *)0)) || (port == ((void *)0)))
  errx(1, "prepare_socket was passed a null arg");
 memset(&cli_hints, 0, sizeof (cli_hints));
 memset(&srv_hints, 0, sizeof (srv_hints));
 cli_hints.ai_family = srv_hints.ai_family = 2;
 srv_hints.ai_flags = 0x0001;
 cli_hints.ai_socktype = srv_hints.ai_socktype =
  ((con->contype == 2) || (con->contype == 3))
  ? SOCK_STREAM : SOCK_DGRAM;
 rv = getaddrinfo(host, port, &cli_hints, &cli_servinfo);
 if (rv)
  errx(1, "getaddrinfo: %s", gai_strerror(rv));
 rv = getaddrinfo(((void *)0), port, &srv_hints, &srv_servinfo);
 if (rv)
  errx(1, "getaddrinfo: %s", gai_strerror(rv));
 for (p0 = cli_servinfo; p0; p0 = p0->ai_next) {
  cli_sockfd = socket(p0->ai_family, p0->ai_socktype,
        p0->ai_protocol);
  if (cli_sockfd < 0)
   continue;
  rv = setsockopt(cli_sockfd, 1,
    2, &optval, sizeof (optval));
  if (rv < 0) {
   close(cli_sockfd);
   warn("setsockopt");
   continue;
  }
  break;
 }
 if (!p0)
  err(1, "socket");
 for (p0 = srv_servinfo; p0; p0 = p0->ai_next) {
  if (bind(cli_sockfd, p0->ai_addr, p0->ai_addrlen) < 0) {
   close(cli_sockfd);
   warn("bind");
   continue;
  }
  break;
 }
 if (!p0)
  err(1, "bind");
 if (con->contype != 1 && lflag)
  listen(cli_sockfd, 5);
 con->confd = cli_sockfd;
 con->clinfo = cli_servinfo;
}

variable_types: struct concontxt_t { unsigned int contype; int confd; int clifd; int clifds[1024]; struct fd_set { long __fds_bits[-1]; } lset; struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *clinfo; struct addrinfo *srvinfo; char *buf; unsigned int buflen; int wfd; } *

variable_types:
host
char *

variable_types:
port
char *

variable_types: lflag int

variable_types: rv int

variable_types: optval int

return_type: void

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

user_defined_types: struct concontxt_t { unsigned int contype; int confd; int clifd; int clifds[1024]; struct fd_set lset; struct addrinfo *clinfo; struct addrinfo *srvinfo; char *buf; unsigned int buflen; int wfd; }


myconnect

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

if ( connect(
*(_DWORD *)(a1 + 4),
*(const struct sockaddr **)(*(_QWORD *)(a1 + 4240) + 24LL),
*(_DWORD *)(*(_QWORD *)(a1 + 4240) + 16LL)) < 0 )
warn("connect");
result = *(unsigned int *)(a1 + 4);
*(_DWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 4) = -1;
return result;
}

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

if ( connect(
*(_DWORD *)(a1 + 4),
*(const struct sockaddr **)(*(_QWORD *)(a1 + 4240) + 24LL),
*(_DWORD *)(*(_QWORD *)(a1 + 4240) + 16LL)) < 0 )
warn("connect");
result = *(unsigned int *)(a1 + 4);
*(_DWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 4) = -1;
return result;
}

original_code:
static void
myconnect(concontxt *con)
{
 int r;
 r = connect(con->confd,
      con->clinfo->ai_addr,
      con->clinfo->ai_addrlen);
 if (r < 0)
  warn("connect");
 con->clifd = con->confd;
 con->confd = -1;
}

canonical_original_code:
static void myconnect(struct concontxt_t *con)
{
 int r;
 r = connect(con->confd,
      con->clinfo->ai_addr,
      con->clinfo->ai_addrlen);
 if (r < 0)
  warn("connect");
 con->clifd = con->confd;
 con->confd = -1;
}

variable_types: r int

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


readstdin

original_code:
static void
readstdin(concontxt *con)
{
 char buf[512];
 ssize_t n;
 do {
  n = read(con->wfd, buf, 512);
  if (n < 0) {
   if ((*__errno_location ()) != 11)
    err(1, "read");
   continue;
  }
  break;
 } while (1);
 buf[n] = '\0';
 if (n == 0 || strncmp(buf, "Q\n", 3) == 0) {
  qflag = 1;
  return;
 }
        printf("n=%zd buf=%s", n, buf);
 if ((con->buf = malloc(n)) == ((void *)0)) {
  warn("malloc");
  goto freex;
 }
 memcpy(con->buf, buf, n);
 con->buflen = n;
 return;
freex:
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}

canonical_original_code:
static void readstdin(struct concontxt_t *con)
{
 char buf[512];
 long n;
 do {
  n = read(con->wfd, buf, 512);
  if (n < 0) {
   if ((*__errno_location ()) != 11)
    err(1, "read");
   continue;
  }
  break;
 } while (1);
 buf[n] = '\0';
 if (n == 0 || strncmp(buf, "Q\n", 3) == 0) {
  qflag = 1;
  return;
 }
        printf("n=%zd buf=%s", n, buf);
 if ((con->buf = malloc(n)) == ((void *)0)) {
  warn("malloc");
  goto freex;
 }
 memcpy(con->buf, buf, n);
 con->buflen = n;
 return;
freex:
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}

variable_types:
buf
char [512]

variable_types: n long


writesock

original_code:
static void
writesock(concontxt *con)
{
 ssize_t n;
 if (con->buf == ((void *)0))
  return;
 if (con->contype == 1) {
         n = sendto(con->confd, con->buf, con->buflen, 0,
      con->clinfo->ai_addr,
      con->clinfo->ai_addrlen);
  if (n < 0)
   warn("sendto");
 } else {
  n = write(con->clifd, con->buf, con->buflen);
  if (n < 0) {
   warn("write");
   close(con->clifd);
   con->clifd = -1;
   goto freex;
  }
 }
freex:
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}

canonical_original_code:
static void writesock(struct concontxt_t *con)
{
 long n;
 if (con->buf == ((void *)0))
  return;
 if (con->contype == 1) {
         n = sendto(con->confd, con->buf, con->buflen, 0,
      con->clinfo->ai_addr,
      con->clinfo->ai_addrlen);
  if (n < 0)
   warn("sendto");
 } else {
  n = write(con->clifd, con->buf, con->buflen);
  if (n < 0) {
   warn("write");
   close(con->clifd);
   con->clifd = -1;
   goto freex;
  }
 }
freex:
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}


writestdout

original_code:
static void
writestdout(concontxt *con)
{
 write(con->lfd, con->buf, con->buflen);
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}

canonical_original_code:
static void writestdout(struct concontxt_t *con)
{
 write(con->lfd, con->buf, con->buflen);
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}


myaccept

decompiled_code:
int __fastcall myaccept(__int64 a1)
{
__int64 v1; // rbx
socklen_t addr_len; // [rsp+Ch] [rbp-4ACh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-4A8h] BYREF
char host[8]; // [rsp+90h] [rbp-428h] BYREF

addr_len = 128;
v1 = (unsigned int)accept(*(_DWORD *)(a1 + 4), &addr, &addr_len);
printf("newfd=%d\n", v1);
if ( (int)v1 < 0 )
err(1, "accept");
*(_DWORD *)(a1 + 8) = v1;
if ( getnameinfo(&addr, addr_len, host, 0x401u, 0LL, 0, 0) < 0 )
{
warn("getnameinfo");
strcpy(host, "unknown");
}
return printf("host=%s\n", host);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
__int64 v1; // rbx
socklen_t addr_len; // [rsp+Ch] [rbp-4ACh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-4A8h] BYREF
char host[8]; // [rsp+90h] [rbp-428h] BYREF

addr_len = 128;
v1 = (unsigned int)accept(*(_DWORD *)(a1 + 4), &addr, &addr_len);
printf("newfd=%d\n", v1);
if ( (int)v1 < 0 )
err(1, "accept");
*(_DWORD *)(a1 + 8) = v1;
if ( getnameinfo(&addr, addr_len, host, 0x401u, 0LL, 0, 0) < 0 )
{
warn("getnameinfo");
strcpy(host, "unknown");
}
return printf("host=%s\n", host);
}

original_code:
static void
myaccept(concontxt *con)
{
 int r;
 char host[1025];
 int newfd;
 struct sockaddr_storage sa;
 socklen_t salen = sizeof (sa);
 newfd = accept(con->confd, (struct sockaddr *)&sa, &salen);
 printf("newfd=%d\n", newfd);
 if (newfd < 0)
  err(1, "accept");
 con->clifd = newfd;
 r = getnameinfo((struct sockaddr *)&sa, salen,
   host, sizeof (host), ((void *)0), 0, 0);
 if (r < 0) {
  warn("getnameinfo");
  snprintf(host, sizeof (host), "unknown");
 }
 printf("host=%s\n", host);
}

canonical_original_code:
static void myaccept(struct concontxt_t *con)
{
 int r;
 char host[1025];
 int newfd;
 struct sockaddr_storage sa;
 unsigned int salen = sizeof (sa);
 newfd = accept(con->confd, (struct sockaddr *)&sa, &salen);
 printf("newfd=%d\n", newfd);
 if (newfd < 0)
  err(1, "accept");
 con->clifd = newfd;
 r = getnameinfo((struct sockaddr *)&sa, salen,
   host, sizeof (host), ((void *)0), 0, 0);
 if (r < 0) {
  warn("getnameinfo");
  snprintf(host, sizeof (host), "unknown");
 }
 printf("host=%s\n", host);
}

variable_types:
host
char [1025]

variable_types: newfd int

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

variable_types:
salen
unsigned int


readsock

decompiled_code:
void __fastcall readsock(__int64 a1)
{
ssize_t v2; // rax
signed __int64 v3; // rbx
void *v4; // rdi
void *v5; // rdi
struct sockaddr sa; // [rsp+0h] [rbp-6B8h] BYREF
socklen_t addr_len; // [rsp+8Ch] [rbp-62Ch] BYREF
char host[8]; // [rsp+90h] [rbp-628h] BYREF
char buf[536]; // [rsp+4A0h] [rbp-218h] BYREF

addr_len = 128;
if ( *(_DWORD *)a1 == 1 )
{
v3 = recvfrom(*(_DWORD *)(a1 + 4), buf, 0x200uLL, 64, &sa, &addr_len);
if ( v3 < 0 )
{
warn("recvfrom");
goto LABEL_14;
}
if ( getnameinfo(&sa, addr_len, host, 0x401u, 0LL, 0, 0) < 0 )
{
warn("getnameinfo");
strcpy(host, "unknown");
}
printf("host=%s\n", host);
}
else
{
while ( 1 )
{
v2 = read(*(_DWORD *)(a1 + 8), buf, 0x200uLL);
v3 = v2;
if ( v2 >= 0 )
break;
if ( *_errno_location() != 11 )
err(1, "read");
}
if ( !v2 )
{
qflag = 1;
close(*(_DWORD *)(a1 + 8));
*(_DWORD *)(a1 + 8) = -1;
goto LABEL_14;
}
}
buf[v3] = 0;
v4 = malloc(v3);
*(_QWORD *)(a1 + 4256) = v4;
if ( v4 )
{
memcpy(v4, buf, v3);
*(_DWORD *)(a1 + 4264) = v3;
printf("n=%zd buf=%s", v3, buf);
return;
}
warn("malloc");
LABEL_14:
v5 = *(void **)(a1 + 4256);
if ( v5 )
free(v5);
*(_QWORD *)(a1 + 4256) = 0LL;
*(_DWORD *)(a1 + 4264) = 0;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
ssize_t v2; // rax
signed __int64 v3; // rbx
void *v4; // rdi
void *v5; // rdi
struct sockaddr sa; // [rsp+0h] [rbp-6B8h] BYREF
socklen_t addr_len; // [rsp+8Ch] [rbp-62Ch] BYREF
char host[8]; // [rsp+90h] [rbp-628h] BYREF
char buf[536]; // [rsp+4A0h] [rbp-218h] BYREF

addr_len = 128;
if ( *(_DWORD *)a1 == 1 )
{
v3 = recvfrom(*(_DWORD *)(a1 + 4), buf, 0x200uLL, 64, &sa, &addr_len);
if ( v3 < 0 )
{
warn("recvfrom");
goto LABEL_14;
}
if ( getnameinfo(&sa, addr_len, host, 0x401u, 0LL, 0, 0) < 0 )
{
warn("getnameinfo");
strcpy(host, "unknown");
}
printf("host=%s\n", host);
}
else
{
while ( 1 )
{
v2 = read(*(_DWORD *)(a1 + 8), buf, 0x200uLL);
v3 = v2;
if ( v2 >= 0 )
break;
if ( *_errno_location() != 11 )
err(1, "read");
}
if ( !v2 )
{
qflag = 1;
close(*(_DWORD *)(a1 + 8));
*(_DWORD *)(a1 + 8) = -1;
goto LABEL_14;
}
}
buf[v3] = 0;
v4 = malloc(v3);
*(_QWORD *)(a1 + 4256) = v4;
if ( v4 )
{
memcpy(v4, buf, v3);
*(_DWORD *)(a1 + 4264) = v3;
printf("n=%zd buf=%s", v3, buf);
return;
}
warn("malloc");
LABEL_14:
v5 = *(void **)(a1 + 4256);
if ( v5 )
free(v5);
*(_QWORD *)(a1 + 4256) = 0LL;
*(_DWORD *)(a1 + 4264) = 0;
}

original_code:
static void
readsock(concontxt *con)
{
 char buf[512];
 ssize_t n;
 int r;
 char host[1025];
 socklen_t addr_len;
 struct sockaddr_storage their_addr;
 addr_len = sizeof (their_addr);
 if (con->contype == 1) {
  n = recvfrom(con->confd, buf, sizeof (buf), MSG_DONTWAIT,
        (struct sockaddr *)&their_addr, &addr_len);
  if (n < 0) {
   warn("recvfrom");
   goto freex;
  }
  r = getnameinfo((struct sockaddr *)&their_addr, addr_len,
    host, sizeof (host), ((void *)0), 0, 0);
  if (r < 0) {
   warn("getnameinfo");
   snprintf(host, sizeof (host), "unknown");
  }
  printf("host=%s\n", host);
 } else {
  do {
   n = read(con->clifd, buf, sizeof (buf));
   if (n < 0) {
    if ((*__errno_location ()) != 11)
     err(1, "read");
    continue;
   }
   if (n == 0) {
    qflag = 1;
    close(con->clifd);
    con->clifd = -1;
    goto freex;
   }
   break;
  } while (1);
 }
 buf[n] = '\0';
 if ((con->buf = malloc(n)) == ((void *)0)) {
  warn("malloc");
  goto freex;
 }
 memcpy(con->buf, buf, n);
 con->buflen = n;
 printf("n=%zd buf=%s", n, buf);
 return;
freex:
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}

canonical_original_code:
static void readsock(struct concontxt_t *con)
{
 char buf[512];
 long n;
 int r;
 char host[1025];
 unsigned int addr_len;
 struct sockaddr_storage their_addr;
 addr_len = sizeof (their_addr);
 if (con->contype == 1) {
  n = recvfrom(con->confd, buf, sizeof (buf), MSG_DONTWAIT,
        (struct sockaddr *)&their_addr, &addr_len);
  if (n < 0) {
   warn("recvfrom");
   goto freex;
  }
  r = getnameinfo((struct sockaddr *)&their_addr, addr_len,
    host, sizeof (host), ((void *)0), 0, 0);
  if (r < 0) {
   warn("getnameinfo");
   snprintf(host, sizeof (host), "unknown");
  }
  printf("host=%s\n", host);
 } else {
  do {
   n = read(con->clifd, buf, sizeof (buf));
   if (n < 0) {
    if ((*__errno_location ()) != 11)
     err(1, "read");
    continue;
   }
   if (n == 0) {
    qflag = 1;
    close(con->clifd);
    con->clifd = -1;
    goto freex;
   }
   break;
  } while (1);
 }
 buf[n] = '\0';
 if ((con->buf = malloc(n)) == ((void *)0)) {
  warn("malloc");
  goto freex;
 }
 memcpy(con->buf, buf, n);
 con->buflen = n;
 printf("n=%zd buf=%s", n, buf);
 return;
freex:
 if (con->buf != ((void *)0))
                free(con->buf);
 con->buf = ((void *)0);
 con->buflen = 0;
}

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


usage

decompiled_code:
size_t __fastcall usage(int a1)
{
size_t result; // rax

result = fwrite(
"usage: nbeng [-ht] rhost rport\n\t-t\tUse TCP for transport\n\t-h\tThis help screen\n",
1uLL,
0x4EuLL,
stderr);
if ( a1 )
exit(1);
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(int a1)
{
size_t result; // rax

result = fwrite(
"usage: nbeng [-ht] rhost rport\n\t-t\tUse TCP for transport\n\t-h\tThis help screen\n",
1uLL,
0x4EuLL,
stderr);
if ( a1 )
exit(1);
return result;
}

original_code:
void
usage(int ret)
{
        fprintf(stderr, "usage: nbeng [-ht] rhost rport\n"
  "\t-t	Use TCP for transport\n"
  "\t-h	This help screen\n");
 if (ret)
  exit(1);
}

variable_types: ret int


main

canonical_name: main

original_code:
int
main(int argc, char *argv[])
{
 int c;
 int highsock, readsocks;
 struct timeval timeout;
 char *host, *port;
 concontxt *con;
 while ((c = getopt(argc, argv, "ht")) != -1) {
  switch (c) {
  case 'h':
   usage(1);
   break;
  case 't':
   tflag = 1;
   break;
  default:
   usage(1);
  }
 }
 argc -= optind;
 argv += optind;
 if (argc != 2)
  usage(1);
 host = argv[0];
 port = argv[1];
 con = malloc(sizeof (concontxt));
 if (con == ((void *)0))
  err(1, "malloc");
 con->wfd = 0;
 con->lfd = 1;
 con->contype = (tflag || sflag) ? 2 : 1;
 con->clifd = -1;
 prepare_socket(con, host, port, 1);
 while (1) {
  timeout.tv_sec = 1;
  timeout.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" (&((&(con->lset))->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&con->lset)->__fds_bits)[((con->wfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->wfd) % (8 * (int) sizeof (__fd_mask)))))));
  highsock = con->wfd;
  if (con->confd != -1) {
   ((void) (((&con->lset)->__fds_bits)[((con->confd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->confd) % (8 * (int) sizeof (__fd_mask)))))));
   highsock = con->confd;
  }
  if (con->clifd != -1) {
   ((void) (((&con->lset)->__fds_bits)[((con->clifd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->clifd) % (8 * (int) sizeof (__fd_mask)))))));
   highsock = con->clifd;
  }
  if (qflag)
   goto freex;
  readsocks = select(highsock + 1, &con->lset, ((void *)0),
       ((void *)0), &timeout);
  if (readsocks < 0) {
   warn("select");
   goto freex;
  }
  if (readsocks != 0) {
   if (((((&con->lset)->__fds_bits)[((con->wfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->wfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    if (con->clifd == -1
        && con->contype != 1) {
     close(con->confd);
     prepare_socket(con, host, port, 0);
     myconnect(con);
    }
    readstdin(con);
    writesock(con);
   }
   if (con->confd != -1 &&
       ((((&con->lset)->__fds_bits)[((con->confd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->confd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    if (con->contype == 1) {
     readsock(con);
     writestdout(con);
    } else {
     myaccept(con);
    }
   }
   if (con->clifd != -1 &&
       ((((&con->lset)->__fds_bits)[((con->clifd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->clifd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    readsock(con);
    writestdout(con);
   }
  }
 }
freex:
 printf("exiting\n");
 if (con != ((void *)0)) {
  close(con->confd);
  close(con->clifd);
  free(con);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int c;
 int highsock; int readsocks;
 struct timeval timeout;
 char *host; char *port;
 struct concontxt_t *con;
 while ((c = getopt(argc, argv, "ht")) != -1) {
  switch (c) {
  case 'h':
   usage(1);
   break;
  case 't':
   tflag = 1;
   break;
  default:
   usage(1);
  }
 }
 argc -= optind;
 argv += optind;
 if (argc != 2)
  usage(1);
 host = argv[0];
 port = argv[1];
 con = malloc(sizeof (concontxt));
 if (con == ((void *)0))
  err(1, "malloc");
 con->wfd = 0;
 con->lfd = 1;
 con->contype = (tflag || sflag) ? 2 : 1;
 con->clifd = -1;
 prepare_socket(con, host, port, 1);
 while (1) {
  timeout.tv_sec = 1;
  timeout.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" (&((&(con->lset))->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&con->lset)->__fds_bits)[((con->wfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->wfd) % (8 * (int) sizeof (__fd_mask)))))));
  highsock = con->wfd;
  if (con->confd != -1) {
   ((void) (((&con->lset)->__fds_bits)[((con->confd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->confd) % (8 * (int) sizeof (__fd_mask)))))));
   highsock = con->confd;
  }
  if (con->clifd != -1) {
   ((void) (((&con->lset)->__fds_bits)[((con->clifd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((con->clifd) % (8 * (int) sizeof (__fd_mask)))))));
   highsock = con->clifd;
  }
  if (qflag)
   goto freex;
  readsocks = select(highsock + 1, &con->lset, ((void *)0),
       ((void *)0), &timeout);
  if (readsocks < 0) {
   warn("select");
   goto freex;
  }
  if (readsocks != 0) {
   if (((((&con->lset)->__fds_bits)[((con->wfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->wfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    if (con->clifd == -1
        && con->contype != 1) {
     close(con->confd);
     prepare_socket(con, host, port, 0);
     myconnect(con);
    }
    readstdin(con);
    writesock(con);
   }
   if (con->confd != -1 &&
       ((((&con->lset)->__fds_bits)[((con->confd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->confd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    if (con->contype == 1) {
     readsock(con);
     writestdout(con);
    } else {
     myaccept(con);
    }
   }
   if (con->clifd != -1 &&
       ((((&con->lset)->__fds_bits)[((con->clifd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((con->clifd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    readsock(con);
    writestdout(con);
   }
  }
 }
freex:
 printf("exiting\n");
 if (con != ((void *)0)) {
  close(con->confd);
  close(con->clifd);
  free(con);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: highsock int

variable_types: readsocks int

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

return_type: int


decompiled_code:
__int64 *x86_bpred_init()
{
__int64 *result; // rax
__int64 v1; // r14
int i; // er13
__int64 v3; // r12
int j; // ebx
__int64 v5; // rbp
char v6[248]; // [rsp+0h] [rbp-F8h] BYREF

x86_bpred_twolevel_l2height = 1 << x86_bpred_twolevel_hist_size;
if ( (x86_bpred_bimod_size & (x86_bpred_bimod_size - 1)) != 0 )
fatal("number of entries in bimodal precitor must be a power of 2");
if ( (x86_bpred_choice_size & (x86_bpred_choice_size - 1)) != 0 )
fatal("number of entries in choice predictor must be power of 2");
if ( (x86_bpred_btb_sets & (x86_bpred_btb_sets - 1)) != 0 )
fatal("number of BTB sets must be a power of 2");
if ( (x86_bpred_btb_assoc & (x86_bpred_btb_assoc - 1)) != 0 )
fatal("BTB associativity must be a power of 2");
if ( (unsigned int)(x86_bpred_twolevel_hist_size - 1) > 0x1D )
fatal("predictor history size must be >=1 and <=30");
if ( (x86_bpred_twolevel_l1size & (x86_bpred_twolevel_l1size - 1)) != 0 )
fatal("two-level predictor sizes must be power of 2");
result = (__int64 *)(unsigned int)x86_bpred_twolevel_l2size;
if ( (x86_bpred_twolevel_l2size & (x86_bpred_twolevel_l2size - 1)) != 0 )
result = (__int64 *)fatal("two-level predictor sizes must be power of 2");
v1 = 0LL;
for ( i = 0; x86_cpu_num_cores > i; v1 += 1824LL )
{
v5 = 0LL;
for ( j = 0; x86_cpu_num_threads > j; v5 += 1904LL )
{
snprintf(v6, 0xC8uLL, "c%dt%d.bpred", (unsigned int)i, (unsigned int)j);
v3 = *(_QWORD *)(*x86_cpu + v1) + v5;
result = x86_bpred_create((__int64)v6);
*(_QWORD *)(v3 + 96) = result;
++j;
}
++i;
}
return result;
}

canonical_decompiled_code:
__int64 *func0()
{
__int64 *result; // rax
__int64 v1; // r14
int i; // er13
__int64 v3; // r12
int j; // ebx
__int64 v5; // rbp
char v6[248]; // [rsp+0h] [rbp-F8h] BYREF

x86_bpred_twolevel_l2height = 1 << x86_bpred_twolevel_hist_size;
if ( (x86_bpred_bimod_size & (x86_bpred_bimod_size - 1)) != 0 )
fatal("number of entries in bimodal precitor must be a power of 2");
if ( (x86_bpred_choice_size & (x86_bpred_choice_size - 1)) != 0 )
fatal("number of entries in choice predictor must be power of 2");
if ( (x86_bpred_btb_sets & (x86_bpred_btb_sets - 1)) != 0 )
fatal("number of BTB sets must be a power of 2");
if ( (x86_bpred_btb_assoc & (x86_bpred_btb_assoc - 1)) != 0 )
fatal("BTB associativity must be a power of 2");
if ( (unsigned int)(x86_bpred_twolevel_hist_size - 1) > 0x1D )
fatal("predictor history size must be >=1 and <=30");
if ( (x86_bpred_twolevel_l1size & (x86_bpred_twolevel_l1size - 1)) != 0 )
fatal("two-level predictor sizes must be power of 2");
result = (__int64 *)(unsigned int)x86_bpred_twolevel_l2size;
if ( (x86_bpred_twolevel_l2size & (x86_bpred_twolevel_l2size - 1)) != 0 )
result = (__int64 *)fatal("two-level predictor sizes must be power of 2");
v1 = 0LL;
for ( i = 0; x86_cpu_num_cores > i; v1 += 1824LL )
{
v5 = 0LL;
for ( j = 0; x86_cpu_num_threads > j; v5 += 1904LL )
{
snprintf(v6, 0xC8uLL, "c%dt%d.bpred", (unsigned int)i, (unsigned int)j);
v3 = *(_QWORD *)(*x86_cpu + v1) + v5;
result = x86_bpred_create((__int64)v6);
*(_QWORD *)(v3 + 96) = result;
++j;
}
++i;
}
return result;
}

original_code:
void x86_bpred_init()
{
 char name[200];
 int core;
 int thread;
 x86_bpred_twolevel_l2height = 1 << x86_bpred_twolevel_hist_size;
 if (x86_bpred_bimod_size & (x86_bpred_bimod_size - 1))
  fatal("number of entries in bimodal precitor must be a power of 2");
 if (x86_bpred_choice_size & (x86_bpred_choice_size - 1))
  fatal("number of entries in choice predictor must be power of 2");
 if (x86_bpred_btb_sets & (x86_bpred_btb_sets - 1))
  fatal("number of BTB sets must be a power of 2");
 if (x86_bpred_btb_assoc & (x86_bpred_btb_assoc - 1))
  fatal("BTB associativity must be a power of 2");
 if (x86_bpred_twolevel_hist_size < 1 || x86_bpred_twolevel_hist_size > 30)
  fatal("predictor history size must be >=1 and <=30");
 if (x86_bpred_twolevel_l1size & (x86_bpred_twolevel_l1size - 1))
  fatal("two-level predictor sizes must be power of 2");
 if (x86_bpred_twolevel_l2size & (x86_bpred_twolevel_l2size - 1))
  fatal("two-level predictor sizes must be power of 2");
 for (core = 0; core < x86_cpu_num_cores; core++) for (thread = 0; thread < x86_cpu_num_threads; thread++)
 {
  snprintf(name, sizeof name, "c%dt%d.bpred", core, thread);
  (x86_cpu->core[core].thread[thread]).bpred = x86_bpred_create(name);
 }
}

variable_types:
name
char [200]

variable_types: core int

variable_types: thread int


decompiled_code:
__int64 __fastcall x86_bpred_free(_QWORD *a1)
{
if ( ((x86_bpred_kind - 3) & 0xFFFFFFFD) != 0 )
{
if ( (unsigned int)(x86_bpred_kind - 4) > 1 )
goto LABEL_3;
}
else
{
mhandle_free(a1[4], "bpred.c:198");
if ( (unsigned int)(x86_bpred_kind - 4) > 1 )
goto LABEL_6;
}
mhandle_free(a1[5], "bpred.c:202");
mhandle_free(a1[6], "bpred.c:203");
LABEL_6:
if ( x86_bpred_kind == 5 )
mhandle_free(a1[7], "bpred.c:208");
LABEL_3:
mhandle_free(*a1, "bpred.c:211");
mhandle_free(a1[3], "bpred.c:212");
mhandle_free(a1[1], "bpred.c:213");
return mhandle_free(a1, "bpred.c:214");
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
if ( ((x86_bpred_kind - 3) & 0xFFFFFFFD) != 0 )
{
if ( (unsigned int)(x86_bpred_kind - 4) > 1 )
goto LABEL_3;
}
else
{
mhandle_free(a1[4], "bpred.c:198");
if ( (unsigned int)(x86_bpred_kind - 4) > 1 )
goto LABEL_6;
}
mhandle_free(a1[5], "bpred.c:202");
mhandle_free(a1[6], "bpred.c:203");
LABEL_6:
if ( x86_bpred_kind == 5 )
mhandle_free(a1[7], "bpred.c:208");
LABEL_3:
mhandle_free(*a1, "bpred.c:211");
mhandle_free(a1[3], "bpred.c:212");
mhandle_free(a1[1], "bpred.c:213");
return mhandle_free(a1, "bpred.c:214");
}

original_code:
void x86_bpred_free(struct x86_bpred_t *bpred)
{
 if (x86_bpred_kind == x86_bpred_kind_bimod || x86_bpred_kind == x86_bpred_kind_comb)
  (mhandle_free(bpred->bimod, "bpred.c" ":" "198"));
 if (x86_bpred_kind == x86_bpred_kind_twolevel || x86_bpred_kind == x86_bpred_kind_comb) {
  (mhandle_free(bpred->twolevel_bht, "bpred.c" ":" "202"));
  (mhandle_free(bpred->twolevel_pht, "bpred.c" ":" "203"));
 }
 if (x86_bpred_kind == x86_bpred_kind_comb)
  (mhandle_free(bpred->choice, "bpred.c" ":" "208"));
 (mhandle_free(bpred->name, "bpred.c" ":" "211"));
 (mhandle_free(bpred->btb, "bpred.c" ":" "212"));
 (mhandle_free(bpred->ras, "bpred.c" ":" "213"));
 (mhandle_free(bpred, "bpred.c" ":" "214"));
}

variable_types: struct x86_bpred_t { char *name; unsigned int *ras; int ras_index; struct btb_entry_t { unsigned int source; unsigned int target; int counter; } *btb; char *bimod; unsigned int *twolevel_bht; char *twolevel_pht; char *choice; long long accesses; long long hits; } *

user_defined_types: struct x86_bpred_t { char *name; unsigned int *ras; int ras_index; struct btb_entry_t *btb; char *bimod; unsigned int *twolevel_bht; char *twolevel_pht; char *choice; long long accesses; long long hits; }


decompiled_code:
__int64 x86_bpred_done()
{
__int64 v0; // rbp
int i; // er12
__int64 result; // rax
__int64 j; // rbx

v0 = 0LL;
for ( i = 0; x86_cpu_num_cores > i; v0 += 1824LL )
{
for ( j = 0LL; x86_cpu_num_threads > (int)j; ++j )
result = x86_bpred_free(*(_QWORD **)(*(_QWORD *)(*x86_cpu + v0) + 1904 * j + 96));
++i;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbp
int i; // er12
__int64 result; // rax
__int64 j; // rbx

v0 = 0LL;
for ( i = 0; x86_cpu_num_cores > i; v0 += 1824LL )
{
for ( j = 0LL; x86_cpu_num_threads > (int)j; ++j )
result = func1(*(_QWORD **)(*(_QWORD *)(*x86_cpu + v0) + 1904 * j + 96));
++i;
}
return result;
}

original_code:
void x86_bpred_done()
{
 int core;
 int thread;
 for (core = 0; core < x86_cpu_num_cores; core++) for (thread = 0; thread < x86_cpu_num_threads; thread++)
  x86_bpred_free((x86_cpu->core[core].thread[thread]).bpred);
}


decompiled_code:
__int64 __fastcall x86_bpred_lookup_multiple(__int64 a1, int a2, int a3)
{
unsigned int v4; // eax
int v5; // er8
__int64 v6; // rbx
unsigned int v7; // esi
int v8; // edx
int v9; // ecx

if ( x86_bpred_kind != 4 )
_assert_fail("x86_bpred_kind == x86_bpred_kind_twolevel", "bpred.c", 0x12Au, "x86_bpred_lookup_multiple");
v4 = *(_DWORD *)(*(_QWORD *)(a1 + 40) + 4LL * (a2 & (unsigned int)(x86_bpred_twolevel_l1size - 1)));
if ( x86_bpred_twolevel_l2height <= v4 )
_assert_fail("bhr < x86_bpred_twolevel_l2height", "bpred.c", 0x12Du, "x86_bpred_lookup_multiple");
v5 = a2 & (x86_bpred_twolevel_l2size - 1);
v6 = *(_QWORD *)(a1 + 48);
v7 = *(_BYTE *)(v6 + v5 + v4 * x86_bpred_twolevel_l2size) > 1;
if ( a3 > 1 )
{
v8 = *(_BYTE *)(v6 + v5 + v4 * x86_bpred_twolevel_l2size) > 1;
v9 = 1;
do
{
v4 = (x86_bpred_twolevel_l2height - 1) & (v8 | (2 * v4));
v8 = *(_BYTE *)(v6 + v5 + v4 * x86_bpred_twolevel_l2size) > 1;
v7 |= v8 << v9++;
}
while ( a3 != v9 );
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, int a3)
{
unsigned int v4; // eax
int v5; // er8
__int64 v6; // rbx
unsigned int v7; // esi
int v8; // edx
int v9; // ecx

if ( x86_bpred_kind != 4 )
_assert_fail("x86_bpred_kind == x86_bpred_kind_twolevel", "bpred.c", 0x12Au, "x86_bpred_lookup_multiple");
v4 = *(_DWORD *)(*(_QWORD *)(a1 + 40) + 4LL * (a2 & (unsigned int)(x86_bpred_twolevel_l1size - 1)));
if ( x86_bpred_twolevel_l2height <= v4 )
_assert_fail("bhr < x86_bpred_twolevel_l2height", "bpred.c", 0x12Du, "x86_bpred_lookup_multiple");
v5 = a2 & (x86_bpred_twolevel_l2size - 1);
v6 = *(_QWORD *)(a1 + 48);
v7 = *(_BYTE *)(v6 + v5 + v4 * x86_bpred_twolevel_l2size) > 1;
if ( a3 > 1 )
{
v8 = *(_BYTE *)(v6 + v5 + v4 * x86_bpred_twolevel_l2size) > 1;
v9 = 1;
do
{
v4 = (x86_bpred_twolevel_l2height - 1) & (v8 | (2 * v4));
v8 = *(_BYTE *)(v6 + v5 + v4 * x86_bpred_twolevel_l2size) > 1;
v7 |= v8 << v9++;
}
while ( a3 != v9 );
}
return v7;
}

original_code:
int x86_bpred_lookup_multiple(struct x86_bpred_t *bpred, uint32_t eip, int count)
{
 int i, pred, temp_pred;
 uint32_t bht_index, pht_col;
 uint32_t bhr;
 ((void) sizeof ((x86_bpred_kind == x86_bpred_kind_twolevel) ? 1 : 0), __extension__ ({ if (x86_bpred_kind == x86_bpred_kind_twolevel) ; else __assert_fail ("x86_bpred_kind == x86_bpred_kind_twolevel", "bpred.c", 298, __extension__ __PRETTY_FUNCTION__); }));
 bht_index = eip & (x86_bpred_twolevel_l1size - 1);
 bhr = bpred->twolevel_bht[bht_index];
 ((void) sizeof ((bhr < x86_bpred_twolevel_l2height) ? 1 : 0), __extension__ ({ if (bhr < x86_bpred_twolevel_l2height) ; else __assert_fail ("bhr < x86_bpred_twolevel_l2height", "bpred.c", 301, __extension__ __PRETTY_FUNCTION__); }));
 pht_col = eip & (x86_bpred_twolevel_l2size - 1);
 pred = temp_pred = bpred->twolevel_pht[bhr * x86_bpred_twolevel_l2size + pht_col] > 1;
 for (i = 1; i < count; i++)
 {
  bhr = ((bhr << 1) | temp_pred) & (x86_bpred_twolevel_l2height - 1);
  temp_pred = bpred->twolevel_pht[bhr * x86_bpred_twolevel_l2size + pht_col] > 1;
  ((void) sizeof ((!temp_pred || temp_pred == 1) ? 1 : 0), __extension__ ({ if (!temp_pred || temp_pred == 1) ; else __assert_fail ("!temp_pred || temp_pred == 1", "bpred.c", 310, __extension__ __PRETTY_FUNCTION__); }));
  pred |= temp_pred << i;
 }
 return pred;
}

canonical_original_code:
int x86_bpred_lookup_multiple(struct x86_bpred_t *bpred, unsigned int eip, int count)
{
 int i; int pred; int temp_pred;
 unsigned int bht_index; unsigned int pht_col;
 unsigned int bhr;
 ((void) sizeof ((x86_bpred_kind == x86_bpred_kind_twolevel) ? 1 : 0), __extension__ ({ if (x86_bpred_kind == x86_bpred_kind_twolevel) ; else __assert_fail ("x86_bpred_kind == x86_bpred_kind_twolevel", "bpred.c", 298, __extension__ __PRETTY_FUNCTION__); }));
 bht_index = eip & (x86_bpred_twolevel_l1size - 1);
 bhr = bpred->twolevel_bht[bht_index];
 ((void) sizeof ((bhr < x86_bpred_twolevel_l2height) ? 1 : 0), __extension__ ({ if (bhr < x86_bpred_twolevel_l2height) ; else __assert_fail ("bhr < x86_bpred_twolevel_l2height", "bpred.c", 301, __extension__ __PRETTY_FUNCTION__); }));
 pht_col = eip & (x86_bpred_twolevel_l2size - 1);
 pred = temp_pred = bpred->twolevel_pht[bhr * x86_bpred_twolevel_l2size + pht_col] > 1;
 for (i = 1; i < count; i++)
 {
  bhr = ((bhr << 1) | temp_pred) & (x86_bpred_twolevel_l2height - 1);
  temp_pred = bpred->twolevel_pht[bhr * x86_bpred_twolevel_l2size + pht_col] > 1;
  ((void) sizeof ((!temp_pred || temp_pred == 1) ? 1 : 0), __extension__ ({ if (!temp_pred || temp_pred == 1) ; else __assert_fail ("!temp_pred || temp_pred == 1", "bpred.c", 310, __extension__ __PRETTY_FUNCTION__); }));
  pred |= temp_pred << i;
 }
 return pred;
}

variable_types:
eip
unsigned int

variable_types: count int

variable_types: i int

variable_types: pred int

variable_types:
bhr
unsigned int

user_defined_types: struct btb_entry_t { unsigned int source; unsigned int target; int counter; }


decompiled_code:
__int64 __fastcall x86_bpred_btb_next_branch(__int64 a1, unsigned int a2, int a3)
{
unsigned int v3; // er9
__int64 v4; // r8
__int64 v5; // rdx
_DWORD *v6; // rax
__int64 v7; // rdx

if ( (a3 & (a3 - 1)) != 0 )
_assert_fail("!(bsize & (bsize - 1))", "bpred.c", 0x1E8u, "x86_bpred_btb_next_branch");
v3 = -a3 & (a3 + a2);
if ( a2 >= v3 )
return 0;
while ( x86_bpred_btb_assoc <= 0 )
{
LABEL_7:
if ( v3 == ++a2 )
return 0;
}
v4 = *(_QWORD *)(a1 + 24);
v5 = (int)(x86_bpred_btb_assoc * (a2 & (x86_bpred_btb_sets - 1)));
v6 = (_DWORD *)(v4 + 12 * v5);
v7 = v4 + 12 * ((unsigned int)(x86_bpred_btb_assoc - 1) + v5) + 12;
while ( *v6 != a2 )
{
v6 += 3;
if ( v6 == (_DWORD *)v7 )
goto LABEL_7;
}
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2, int a3)
{
unsigned int v3; // er9
__int64 v4; // r8
__int64 v5; // rdx
_DWORD *v6; // rax
__int64 v7; // rdx

if ( (a3 & (a3 - 1)) != 0 )
_assert_fail("!(bsize & (bsize - 1))", "bpred.c", 0x1E8u, "x86_bpred_btb_next_branch");
v3 = -a3 & (a3 + a2);
if ( a2 >= v3 )
return 0;
while ( x86_bpred_btb_assoc <= 0 )
{
LABEL_7:
if ( v3 == ++a2 )
return 0;
}
v4 = *(_QWORD *)(a1 + 24);
v5 = (int)(x86_bpred_btb_assoc * (a2 & (x86_bpred_btb_sets - 1)));
v6 = (_DWORD *)(v4 + 12 * v5);
v7 = v4 + 12 * ((unsigned int)(x86_bpred_btb_assoc - 1) + v5) + 12;
while ( *v6 != a2 )
{
v6 += 3;
if ( v6 == (_DWORD *)v7 )
goto LABEL_7;
}
return a2;
}

original_code:
unsigned int x86_bpred_btb_next_branch(struct x86_bpred_t *bpred, uint32_t eip, uint32_t bsize)
{
 struct btb_entry_t *entry;
 uint32_t limit;
 int set, way;
 ((void) sizeof ((!(bsize & (bsize - 1))) ? 1 : 0), __extension__ ({ if (!(bsize & (bsize - 1))) ; else __assert_fail ("!(bsize & (bsize - 1))", "bpred.c", 488, __extension__ __PRETTY_FUNCTION__); }));
 limit = (eip + bsize) & ~(bsize - 1);
 while (eip < limit) {
  set = eip & (x86_bpred_btb_sets - 1);
  for (way = 0; way < x86_bpred_btb_assoc; way++)
  {
   entry = (&bpred->btb[(set) * x86_bpred_btb_assoc + (way)]);
   if (entry->source == eip)
    return eip;
  }
  eip++;
 }
 return 0;
}

canonical_original_code:
unsigned int x86_bpred_btb_next_branch(struct x86_bpred_t *bpred, unsigned int eip, unsigned int bsize)
{
 struct btb_entry_t *entry;
 unsigned int limit;
 int set; int way;
 ((void) sizeof ((!(bsize & (bsize - 1))) ? 1 : 0), __extension__ ({ if (!(bsize & (bsize - 1))) ; else __assert_fail ("!(bsize & (bsize - 1))", "bpred.c", 488, __extension__ __PRETTY_FUNCTION__); }));
 limit = (eip + bsize) & ~(bsize - 1);
 while (eip < limit) {
  set = eip & (x86_bpred_btb_sets - 1);
  for (way = 0; way < x86_bpred_btb_assoc; way++)
  {
   entry = (&bpred->btb[(set) * x86_bpred_btb_assoc + (way)]);
   if (entry->source == eip)
    return eip;
  }
  eip++;
 }
 return 0;
}

variable_types:
bsize
unsigned int

variable_types: struct btb_entry_t { unsigned int source; unsigned int target; int counter; } *

variable_types:
limit
unsigned int

variable_types: set int

variable_types: way int

return_type: unsigned int


decompiled_code:
_QWORD *frm_isa_init()
{
_QWORD *result; // rax

frm_isa_inst_func = mhandle_calloc(70LL, 8LL, "isa.c:40");
if ( !frm_isa_inst_func )
fatal("%s: out of memory", "frm_isa_init");
result = (_QWORD *)frm_isa_inst_func;
*(_QWORD *)(frm_isa_inst_func + 8) = &frm_isa_FFMA_impl;
result[2] = &frm_isa_FADD_impl;
result[3] = &frm_isa_FADD32I_impl;
result[4] = &frm_isa_FCMP_impl;
result[5] = &frm_isa_FMUL_impl;
result[6] = &frm_isa_FMUL32I_impl;
result[7] = &frm_isa_FSETP_impl;
result[8] = &frm_isa_MUFU_impl;
result[9] = &frm_isa_DFMA_impl;
result[10] = &frm_isa_DADD_impl;
result[11] = &frm_isa_DMUL_impl;
result[12] = &frm_isa_DSETP_impl;
result[13] = &frm_isa_IMAD_impl;
result[14] = &frm_isa_IMUL_impl;
result[15] = &frm_isa_IADD_impl;
result[16] = &frm_isa_IADD32I_impl;
result[17] = &frm_isa_ISCADD_impl;
result[18] = &frm_isa_BFE_impl;
result[19] = &frm_isa_BFI_impl;
result[20] = &frm_isa_SHR_impl;
result[21] = &frm_isa_SHL_impl;
result[22] = &frm_isa_LOP_impl;
result[23] = &frm_isa_LOP32I_impl;
result[24] = &frm_isa_ISETP_impl;
result[25] = &frm_isa_ICMP_impl;
result[26] = &frm_isa_F2F_impl;
result[27] = &frm_isa_F2I_impl;
result[28] = &frm_isa_I2F_impl;
result[29] = &frm_isa_I2I_impl;
result[30] = &frm_isa_MOV_impl;
result[31] = &frm_isa_MOV32I_impl;
result[32] = &frm_isa_SEL_impl;
result[33] = &frm_isa_LDC_impl;
result[34] = &frm_isa_LD_impl;
result[35] = &frm_isa_LDU_impl;
result[36] = &frm_isa_LDL_impl;
result[37] = &frm_isa_LDS_impl;
result[38] = &frm_isa_LDLK_impl;
result[39] = &frm_isa_LDSLK_impl;
result[40] = &frm_isa_ST_impl;
result[41] = &frm_isa_STL_impl;
result[42] = &frm_isa_STUL_impl;
result[43] = &frm_isa_STS_impl;
result[44] = &frm_isa_STSUL_impl;
result[45] = &frm_isa_ATOM_impl;
result[46] = &frm_isa_RED_impl;
result[47] = &frm_isa_CCTL_impl;
result[48] = &frm_isa_CCTLL_impl;
result[49] = &frm_isa_MEMBAR_impl;
result[50] = &frm_isa_BRA_impl;
result[51] = &frm_isa_JMP_impl;
result[52] = &frm_isa_CAL_impl;
result[53] = &frm_isa_JCAL_impl;
result[54] = &frm_isa_RET_impl;
result[55] = &frm_isa_BRK_impl;
result[56] = &frm_isa_CONT_impl;
result[57] = &frm_isa_LONGJMP_impl;
result[58] = &frm_isa_SSY_impl;
result[59] = &frm_isa_PBK_impl;
result[60] = &frm_isa_PCNT_impl;
result[61] = &frm_isa_PRET_impl;
result[62] = &frm_isa_PLONGJMP_impl;
result[63] = &frm_isa_EXIT_impl;
result[64] = &frm_isa_NOP_impl;
result[65] = &frm_isa_S2R_impl;
result[66] = &frm_isa_B2R_impl;
result[67] = &frm_isa_LEPC_impl;
result[68] = &frm_isa_BAR_impl;
result[69] = &frm_isa_VOTE_impl;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

frm_isa_inst_func = mhandle_calloc(70LL, 8LL, "isa.c:40");
if ( !frm_isa_inst_func )
fatal("%s: out of memory", "frm_isa_init");
result = (_QWORD *)frm_isa_inst_func;
*(_QWORD *)(frm_isa_inst_func + 8) = &frm_isa_FFMA_impl;
result[2] = &frm_isa_FADD_impl;
result[3] = &frm_isa_FADD32I_impl;
result[4] = &frm_isa_FCMP_impl;
result[5] = &frm_isa_FMUL_impl;
result[6] = &frm_isa_FMUL32I_impl;
result[7] = &frm_isa_FSETP_impl;
result[8] = &frm_isa_MUFU_impl;
result[9] = &frm_isa_DFMA_impl;
result[10] = &frm_isa_DADD_impl;
result[11] = &frm_isa_DMUL_impl;
result[12] = &frm_isa_DSETP_impl;
result[13] = &frm_isa_IMAD_impl;
result[14] = &frm_isa_IMUL_impl;
result[15] = &frm_isa_IADD_impl;
result[16] = &frm_isa_IADD32I_impl;
result[17] = &frm_isa_ISCADD_impl;
result[18] = &frm_isa_BFE_impl;
result[19] = &frm_isa_BFI_impl;
result[20] = &frm_isa_SHR_impl;
result[21] = &frm_isa_SHL_impl;
result[22] = &frm_isa_LOP_impl;
result[23] = &frm_isa_LOP32I_impl;
result[24] = &frm_isa_ISETP_impl;
result[25] = &frm_isa_ICMP_impl;
result[26] = &frm_isa_F2F_impl;
result[27] = &frm_isa_F2I_impl;
result[28] = &frm_isa_I2F_impl;
result[29] = &frm_isa_I2I_impl;
result[30] = &frm_isa_MOV_impl;
result[31] = &frm_isa_MOV32I_impl;
result[32] = &frm_isa_SEL_impl;
result[33] = &frm_isa_LDC_impl;
result[34] = &frm_isa_LD_impl;
result[35] = &frm_isa_LDU_impl;
result[36] = &frm_isa_LDL_impl;
result[37] = &frm_isa_LDS_impl;
result[38] = &frm_isa_LDLK_impl;
result[39] = &frm_isa_LDSLK_impl;
result[40] = &frm_isa_ST_impl;
result[41] = &frm_isa_STL_impl;
result[42] = &frm_isa_STUL_impl;
result[43] = &frm_isa_STS_impl;
result[44] = &frm_isa_STSUL_impl;
result[45] = &frm_isa_ATOM_impl;
result[46] = &frm_isa_RED_impl;
result[47] = &frm_isa_CCTL_impl;
result[48] = &frm_isa_CCTLL_impl;
result[49] = &frm_isa_MEMBAR_impl;
result[50] = &frm_isa_BRA_impl;
result[51] = &frm_isa_JMP_impl;
result[52] = &frm_isa_CAL_impl;
result[53] = &frm_isa_JCAL_impl;
result[54] = &frm_isa_RET_impl;
result[55] = &frm_isa_BRK_impl;
result[56] = &frm_isa_CONT_impl;
result[57] = &frm_isa_LONGJMP_impl;
result[58] = &frm_isa_SSY_impl;
result[59] = &frm_isa_PBK_impl;
result[60] = &frm_isa_PCNT_impl;
result[61] = &frm_isa_PRET_impl;
result[62] = &frm_isa_PLONGJMP_impl;
result[63] = &frm_isa_EXIT_impl;
result[64] = &frm_isa_NOP_impl;
result[65] = &frm_isa_S2R_impl;
result[66] = &frm_isa_B2R_impl;
result[67] = &frm_isa_LEPC_impl;
result[68] = &frm_isa_BAR_impl;
result[69] = &frm_isa_VOTE_impl;
return result;
}

original_code:
void frm_isa_init()
{
 frm_isa_inst_func = (mhandle_calloc(FRM_INST_COUNT, sizeof(frm_isa_inst_func_t), "isa.c" ":" "40"));
 if (!frm_isa_inst_func)
  fatal("%s: out of memory", __FUNCTION__);
frm_isa_inst_func[FRM_INST_FFMA] = frm_isa_FFMA_impl;
frm_isa_inst_func[FRM_INST_FADD] = frm_isa_FADD_impl;
frm_isa_inst_func[FRM_INST_FADD32I] = frm_isa_FADD32I_impl;
frm_isa_inst_func[FRM_INST_FCMP] = frm_isa_FCMP_impl;
frm_isa_inst_func[FRM_INST_FMUL] = frm_isa_FMUL_impl;
frm_isa_inst_func[FRM_INST_FMUL32I] = frm_isa_FMUL32I_impl;
frm_isa_inst_func[FRM_INST_FSETP] = frm_isa_FSETP_impl;
frm_isa_inst_func[FRM_INST_MUFU] = frm_isa_MUFU_impl;
frm_isa_inst_func[FRM_INST_DFMA] = frm_isa_DFMA_impl;
frm_isa_inst_func[FRM_INST_DADD] = frm_isa_DADD_impl;
frm_isa_inst_func[FRM_INST_DMUL] = frm_isa_DMUL_impl;
frm_isa_inst_func[FRM_INST_DSETP] = frm_isa_DSETP_impl;
frm_isa_inst_func[FRM_INST_IMAD] = frm_isa_IMAD_impl;
frm_isa_inst_func[FRM_INST_IMUL] = frm_isa_IMUL_impl;
frm_isa_inst_func[FRM_INST_IADD] = frm_isa_IADD_impl;
frm_isa_inst_func[FRM_INST_IADD32I] = frm_isa_IADD32I_impl;
frm_isa_inst_func[FRM_INST_ISCADD] = frm_isa_ISCADD_impl;
frm_isa_inst_func[FRM_INST_BFE] = frm_isa_BFE_impl;
frm_isa_inst_func[FRM_INST_BFI] = frm_isa_BFI_impl;
frm_isa_inst_func[FRM_INST_SHR] = frm_isa_SHR_impl;
frm_isa_inst_func[FRM_INST_SHL] = frm_isa_SHL_impl;
frm_isa_inst_func[FRM_INST_LOP] = frm_isa_LOP_impl;
frm_isa_inst_func[FRM_INST_LOP32I] = frm_isa_LOP32I_impl;
frm_isa_inst_func[FRM_INST_ISETP] = frm_isa_ISETP_impl;
frm_isa_inst_func[FRM_INST_ICMP] = frm_isa_ICMP_impl;
frm_isa_inst_func[FRM_INST_F2F] = frm_isa_F2F_impl;
frm_isa_inst_func[FRM_INST_F2I] = frm_isa_F2I_impl;
frm_isa_inst_func[FRM_INST_I2F] = frm_isa_I2F_impl;
frm_isa_inst_func[FRM_INST_I2I] = frm_isa_I2I_impl;
frm_isa_inst_func[FRM_INST_MOV] = frm_isa_MOV_impl;
frm_isa_inst_func[FRM_INST_MOV32I] = frm_isa_MOV32I_impl;
frm_isa_inst_func[FRM_INST_SEL] = frm_isa_SEL_impl;
frm_isa_inst_func[FRM_INST_LDC] = frm_isa_LDC_impl;
frm_isa_inst_func[FRM_INST_LD] = frm_isa_LD_impl;
frm_isa_inst_func[FRM_INST_LDU] = frm_isa_LDU_impl;
frm_isa_inst_func[FRM_INST_LDL] = frm_isa_LDL_impl;
frm_isa_inst_func[FRM_INST_LDS] = frm_isa_LDS_impl;
frm_isa_inst_func[FRM_INST_LDLK] = frm_isa_LDLK_impl;
frm_isa_inst_func[FRM_INST_LDSLK] = frm_isa_LDSLK_impl;
frm_isa_inst_func[FRM_INST_ST] = frm_isa_ST_impl;
frm_isa_inst_func[FRM_INST_STL] = frm_isa_STL_impl;
frm_isa_inst_func[FRM_INST_STUL] = frm_isa_STUL_impl;
frm_isa_inst_func[FRM_INST_STS] = frm_isa_STS_impl;
frm_isa_inst_func[FRM_INST_STSUL] = frm_isa_STSUL_impl;
frm_isa_inst_func[FRM_INST_ATOM] = frm_isa_ATOM_impl;
frm_isa_inst_func[FRM_INST_RED] = frm_isa_RED_impl;
frm_isa_inst_func[FRM_INST_CCTL] = frm_isa_CCTL_impl;
frm_isa_inst_func[FRM_INST_CCTLL] = frm_isa_CCTLL_impl;
frm_isa_inst_func[FRM_INST_MEMBAR] = frm_isa_MEMBAR_impl;
frm_isa_inst_func[FRM_INST_BRA] = frm_isa_BRA_impl;
frm_isa_inst_func[FRM_INST_JMP] = frm_isa_JMP_impl;
frm_isa_inst_func[FRM_INST_CAL] = frm_isa_CAL_impl;
frm_isa_inst_func[FRM_INST_JCAL] = frm_isa_JCAL_impl;
frm_isa_inst_func[FRM_INST_RET] = frm_isa_RET_impl;
frm_isa_inst_func[FRM_INST_BRK] = frm_isa_BRK_impl;
frm_isa_inst_func[FRM_INST_CONT] = frm_isa_CONT_impl;
frm_isa_inst_func[FRM_INST_LONGJMP] = frm_isa_LONGJMP_impl;
frm_isa_inst_func[FRM_INST_SSY] = frm_isa_SSY_impl;
frm_isa_inst_func[FRM_INST_PBK] = frm_isa_PBK_impl;
frm_isa_inst_func[FRM_INST_PCNT] = frm_isa_PCNT_impl;
frm_isa_inst_func[FRM_INST_PRET] = frm_isa_PRET_impl;
frm_isa_inst_func[FRM_INST_PLONGJMP] = frm_isa_PLONGJMP_impl;
frm_isa_inst_func[FRM_INST_EXIT] = frm_isa_EXIT_impl;
frm_isa_inst_func[FRM_INST_NOP] = frm_isa_NOP_impl;
frm_isa_inst_func[FRM_INST_S2R] = frm_isa_S2R_impl;
frm_isa_inst_func[FRM_INST_B2R] = frm_isa_B2R_impl;
frm_isa_inst_func[FRM_INST_LEPC] = frm_isa_LEPC_impl;
frm_isa_inst_func[FRM_INST_BAR] = frm_isa_BAR_impl;
frm_isa_inst_func[FRM_INST_VOTE] = frm_isa_VOTE_impl;
}


decompiled_code:
__int64 frm_isa_done()
{
return mhandle_free(frm_isa_inst_func, "isa.c:55");
}

canonical_decompiled_code:
__int64 func1()
{
return mhandle_free(frm_isa_inst_func, "isa.c:55");
}

original_code:
void frm_isa_done()
{
 (mhandle_free(frm_isa_inst_func, "isa.c" ":" "55"));
}


decompiled_code:
__int64 __fastcall frm_isa_global_mem_write(unsigned int a1, __int64 a2)
{
return mem_write(*(_QWORD *)(frm_emu + 232LL), a1, 4LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
return mem_write(*(_QWORD *)(frm_emu + 232LL), a1, 4LL, a2);
}

original_code:
void frm_isa_global_mem_write(unsigned int addr, void *pvalue)
{
 mem_write(frm_emu->global_mem, addr, sizeof(unsigned int), pvalue);
}

variable_types:
addr
unsigned int

variable_types:
pvalue
void *


decompiled_code:
__int64 __fastcall frm_isa_global_mem_read(unsigned int a1, __int64 a2)
{
return mem_read(*(_QWORD *)(frm_emu + 232LL), a1, 4LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2)
{
return mem_read(*(_QWORD *)(frm_emu + 232LL), a1, 4LL, a2);
}

original_code:
void frm_isa_global_mem_read(unsigned int addr, void *pvalue)
{
 mem_read(frm_emu->global_mem, addr, sizeof(unsigned int), pvalue);
}


decompiled_code:
__int64 __fastcall frm_isa_const_mem_write(unsigned int a1, __int64 a2)
{
if ( a1 <= 0x1F )
*(_DWORD *)(frm_emu + 4LL * a1 + 104) = 1;
return mem_write(*(_QWORD *)(frm_emu + 96LL), a1, 4LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2)
{
if ( a1 <= 0x1F )
*(_DWORD *)(frm_emu + 4LL * a1 + 104) = 1;
return mem_write(*(_QWORD *)(frm_emu + 96LL), a1, 4LL, a2);
}

original_code:
void frm_isa_const_mem_write(unsigned int addr, void *pvalue)
{
 if (addr < 0x20)
  frm_emu->const_mem_init[addr] = 1;
 mem_write(frm_emu->const_mem, addr, sizeof(unsigned int), pvalue);
}


decompiled_code:
__int64 __fastcall frm_isa_const_mem_read(unsigned int a1, __int64 a2)
{
if ( a1 <= 0x1F && !*(_DWORD *)(frm_emu + 4LL * a1 + 104) )
warning("c [0] [0x%x] is used uninitialized", a1);
return mem_read(*(_QWORD *)(frm_emu + 96LL), a1, 4LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, __int64 a2)
{
if ( a1 <= 0x1F && !*(_DWORD *)(frm_emu + 4LL * a1 + 104) )
warning("c [0] [0x%x] is used uninitialized", a1);
return mem_read(*(_QWORD *)(frm_emu + 96LL), a1, 4LL, a2);
}

original_code:
void frm_isa_const_mem_read(unsigned int addr, void *pvalue)
{
 if (addr < 0x20 && !frm_emu->const_mem_init[addr])
  warning("c [0] [0x%x] is used uninitialized", addr);
 mem_read(frm_emu->const_mem, addr, sizeof(unsigned int), pvalue);
}


decompiled_code:
__int64 __fastcall frm_cuda_object_add(__int64 a1)
{
linked_list_find(frm_cuda_object_list, a1);
if ( !*(_DWORD *)(frm_cuda_object_list + 4) )
_assert_fail("frm_cuda_object_list->error_code", "cuda-obj.c", 0x2Au, "frm_cuda_object_add");
return linked_list_add(frm_cuda_object_list, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
linked_list_find(frm_cuda_object_list, a1);
if ( !*(_DWORD *)(frm_cuda_object_list + 4) )
_assert_fail("frm_cuda_object_list->error_code", "cuda-obj.c", 0x2Au, "frm_cuda_object_add");
return linked_list_add(frm_cuda_object_list, a1);
}

original_code:
void frm_cuda_object_add(void *object)
{
 linked_list_find(frm_cuda_object_list, object);
 ((void) sizeof ((frm_cuda_object_list->error_code) ? 1 : 0), __extension__ ({ if (frm_cuda_object_list->error_code) ; else __assert_fail ("frm_cuda_object_list->error_code", "cuda-obj.c", 42, __extension__ __PRETTY_FUNCTION__); }));
 linked_list_add(frm_cuda_object_list, object);
}

variable_types:
object
void *


decompiled_code:
__int64 __fastcall frm_cuda_object_remove(__int64 a1)
{
linked_list_find(frm_cuda_object_list, a1);
if ( *(_DWORD *)(frm_cuda_object_list + 4) )
_assert_fail("!frm_cuda_object_list->error_code", "cuda-obj.c", 0x34u, "frm_cuda_object_remove");
return linked_list_remove();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
linked_list_find(frm_cuda_object_list, a1);
if ( *(_DWORD *)(frm_cuda_object_list + 4) )
_assert_fail("!frm_cuda_object_list->error_code", "cuda-obj.c", 0x34u, "frm_cuda_object_remove");
return linked_list_remove();
}

original_code:
void frm_cuda_object_remove(void *object)
{
 linked_list_find(frm_cuda_object_list, object);
 ((void) sizeof ((!frm_cuda_object_list->error_code) ? 1 : 0), __extension__ ({ if (!frm_cuda_object_list->error_code) ; else __assert_fail ("!frm_cuda_object_list->error_code", "cuda-obj.c", 52, __extension__ __PRETTY_FUNCTION__); }));
 linked_list_remove(frm_cuda_object_list);
}


decompiled_code:
__int64 __fastcall frm_cuda_object_new_id(int a1)
{
unsigned int v1; // ebx

v1 = cuda_current_object_id_7++ | (a1 << 16);
if ( (unsigned int)cuda_current_object_id_7 > 0xFFFF )
fatal("cuda_object_new_id: too many CUDA objects");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
unsigned int v1; // ebx

v1 = cuda_current_object_id_7++ | (a1 << 16);
if ( (unsigned int)cuda_current_object_id_7 > 0xFFFF )
fatal("cuda_object_new_id: too many CUDA objects");
return v1;
}

original_code:
unsigned int frm_cuda_object_new_id(enum frm_cuda_obj_t type)
{
 static unsigned int cuda_current_object_id;
 unsigned int id;
 id = (type << 16) | cuda_current_object_id;
 cuda_current_object_id++;
 if (cuda_current_object_id > 0xffff)
  fatal("cuda_object_new_id: too many CUDA objects");
 return id;
}

variable_types: enum frm_cuda_obj_t { FRM_CUDA_OBJ_DEVICE=1, FRM_CUDA_OBJ_CONTEXT=2, FRM_CUDA_OBJ_MODULE=3, FRM_CUDA_OBJ_FUNCTION=4, FRM_CUDA_OBJ_MEMORY=5, FRM_CUDA_OBJ_STREAM=6 }

variable_types:
id
unsigned int


decompiled_code:
_DWORD *frm_cuda_device_create()
{
_DWORD *v0; // rbx

v0 = (_DWORD *)mhandle_calloc(1LL, 4LL, "cuda-obj.c:170");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_device_create");
*v0 = frm_cuda_object_new_id(1);
frm_cuda_object_add((__int64)v0);
return v0;
}

canonical_decompiled_code:
_DWORD *func3()
{
_DWORD *v0; // rbx

v0 = (_DWORD *)mhandle_calloc(1LL, 4LL, "cuda-obj.c:170");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_device_create");
*v0 = func2(1);
func0((__int64)v0);
return v0;
}

original_code:
struct frm_cuda_device_t *frm_cuda_device_create()
{
 struct frm_cuda_device_t *device;
 device = (mhandle_calloc(1, sizeof(struct frm_cuda_device_t), "cuda-obj.c" ":" "170"));
 if (!device)
  fatal("%s: out of memory", __FUNCTION__);
 device->id = frm_cuda_object_new_id(FRM_CUDA_OBJ_DEVICE);
 frm_cuda_object_add(device);
 return device;
}

variable_types: struct frm_cuda_device_t { unsigned int id; } *


decompiled_code:
__int64 __fastcall frm_cuda_device_free(__int64 a1)
{
frm_cuda_object_remove(a1);
return mhandle_free(a1, "cuda-obj.c:188");
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
func1(a1);
return mhandle_free(a1, "cuda-obj.c:188");
}

original_code:
void frm_cuda_device_free(struct frm_cuda_device_t *device)
{
 frm_cuda_object_remove(device);
 (mhandle_free(device, "cuda-obj.c" ":" "188"));
}

user_defined_types: struct frm_cuda_device_t { unsigned int id; }


decompiled_code:
_DWORD *frm_cuda_context_create()
{
_DWORD *v0; // rbx

v0 = (_DWORD *)mhandle_calloc(1LL, 12LL, "cuda-obj.c:205");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_context_create");
*v0 = frm_cuda_object_new_id(2);
v0[1] = 1;
frm_cuda_object_add((__int64)v0);
return v0;
}

canonical_decompiled_code:
_DWORD *func5()
{
_DWORD *v0; // rbx

v0 = (_DWORD *)mhandle_calloc(1LL, 12LL, "cuda-obj.c:205");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_context_create");
*v0 = func2(2);
v0[1] = 1;
func0((__int64)v0);
return v0;
}

original_code:
struct frm_cuda_context_t *frm_cuda_context_create()
{
 struct frm_cuda_context_t *context;
 context = (mhandle_calloc(1, sizeof(struct frm_cuda_context_t), "cuda-obj.c" ":" "205"));
 if (!context)
  fatal("%s: out of memory", __FUNCTION__);
 context->id = frm_cuda_object_new_id(FRM_CUDA_OBJ_CONTEXT);
 context->ref_count = 1;
 frm_cuda_object_add(context);
 return context;
}

variable_types: struct frm_cuda_context_t { unsigned int id; int ref_count; unsigned int device_id; } *


decompiled_code:
__int64 __fastcall frm_cuda_context_free(__int64 a1)
{
frm_cuda_object_remove(a1);
return mhandle_free(a1, "cuda-obj.c:224");
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
func1(a1);
return mhandle_free(a1, "cuda-obj.c:224");
}

original_code:
void frm_cuda_context_free(struct frm_cuda_context_t *context)
{
 frm_cuda_object_remove(context);
 (mhandle_free(context, "cuda-obj.c" ":" "224"));
}

user_defined_types: struct frm_cuda_context_t { unsigned int id; int ref_count; unsigned int device_id; }


decompiled_code:
_DWORD *frm_cuda_module_create()
{
_DWORD *v0; // rbx

v0 = (_DWORD *)mhandle_calloc(1LL, 24LL, "cuda-obj.c:241");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_module_create");
*v0 = frm_cuda_object_new_id(3);
v0[1] = 1;
frm_cuda_object_add((__int64)v0);
return v0;
}

canonical_decompiled_code:
_DWORD *func7()
{
_DWORD *v0; // rbx

v0 = (_DWORD *)mhandle_calloc(1LL, 24LL, "cuda-obj.c:241");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_module_create");
*v0 = func2(3);
v0[1] = 1;
func0((__int64)v0);
return v0;
}

original_code:
struct frm_cuda_module_t *frm_cuda_module_create()
{
 struct frm_cuda_module_t *module;
 module = (mhandle_calloc(1, sizeof(struct frm_cuda_module_t), "cuda-obj.c" ":" "241"));
 if (!module)
  fatal("%s: out of memory", __FUNCTION__);
 module->id = frm_cuda_object_new_id(FRM_CUDA_OBJ_MODULE);
 module->ref_count = 1;
 frm_cuda_object_add(module);
 return module;
}

variable_types: struct frm_cuda_module_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; struct elf_file_t { char *path; struct elf_buffer_t { void *ptr; int size; int pos; } buffer; struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *header; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *section_list; struct elf_section_t { char *name; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *header; struct elf_buffer_t buffer; } *string_table; struct list_t *program_header_list; struct list_t *symbol_table; } *elf_file; } *

user_defined_types: struct frm_cuda_module_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; struct elf_file_t *elf_file; }

user_defined_types: struct elf_file_t { char *path; struct elf_buffer_t buffer; struct Elf32_Ehdr *header; struct list_t *section_list; struct elf_section_t *string_table; struct list_t *program_header_list; struct list_t *symbol_table; }

user_defined_types: struct elf_section_t { char *name; struct Elf32_Shdr *header; struct elf_buffer_t buffer; }


decompiled_code:
__int64 __fastcall frm_cuda_module_free(__int64 a1)
{
if ( *(_QWORD *)(a1 + 16) )
elf_file_free();
frm_cuda_object_remove(a1);
return mhandle_free(a1, "cuda-obj.c:262");
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
if ( *(_QWORD *)(a1 + 16) )
elf_file_free();
func1(a1);
return mhandle_free(a1, "cuda-obj.c:262");
}

original_code:
void frm_cuda_module_free(struct frm_cuda_module_t *module)
{
 if (module->elf_file)
  elf_file_free(module->elf_file);
 frm_cuda_object_remove(module);
 (mhandle_free(module, "cuda-obj.c" ":" "262"));
}

user_defined_types: struct elf_buffer_t { void *ptr; int size; int pos; }

user_defined_types: struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; }

user_defined_types: struct list_t { int count; int error_code; int size; int head; int tail; void **elem; }

user_defined_types: struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; }


decompiled_code:
__int64 __fastcall frm_cuda_function_arg_create(char *src)
{
size_t v1; // rax
__int64 v2; // rbx

v1 = strlen(src);
v2 = mhandle_calloc(1LL, v1 + 221, "cuda-obj.c:277");
if ( !v2 )
fatal("%s: out of memory", "frm_cuda_function_arg_create");
strncpy((char *)(v2 + 4), src, 0xC8uLL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *src)
{
size_t v1; // rax
__int64 v2; // rbx

v1 = strlen(src);
v2 = mhandle_calloc(1LL, v1 + 221, "cuda-obj.c:277");
if ( !v2 )
fatal("%s: out of memory", "frm_cuda_function_arg_create");
strncpy((char *)(v2 + 4), src, 0xC8uLL);
return v2;
}

original_code:
struct frm_cuda_function_arg_t *frm_cuda_function_arg_create(char *name)
{
 struct frm_cuda_function_arg_t *arg;
 arg = (mhandle_calloc(1, sizeof(struct frm_cuda_function_arg_t) + strlen(name) + 1, "cuda-obj.c" ":" "277"));
 if (!arg)
  fatal("%s: out of memory", __FUNCTION__);
 strncpy(arg->name, name, 200);
 return arg;
}

variable_types:
name
char *

variable_types: struct frm_cuda_function_arg_t { int id; char name[200]; enum frm_cuda_function_arg_kind_t { FRM_CUDA_FUNCTION_ARG_KIND_VALUE=1, FRM_CUDA_FUNCTION_ARG_KIND_POINTER=2 } kind; enum frm_cuda_mem_scope_t { FRM_CUDA_MEM_SCOPE_NONE=0, FRM_CUDA_MEM_SCOPE_GLOBAL=1, FRM_CUDA_MEM_SCOPE_LOCAL=2, FRM_CUDA_MEM_SCOPE_PRIVATE=3, FRM_CUDA_MEM_SCOPE_CONSTANT=4 } mem_scope; enum frm_cuda_function_arg_access_type_t { FRM_CUDA_FUNCTION_ARG_READ_ONLY=1, FRM_CUDA_FUNCTION_ARG_WRITE_ONLY=2, FRM_CUDA_FUNCTION_ARG_READ_WRITE=3 } access_type; unsigned int value; } *

user_defined_types: struct frm_cuda_function_arg_t { int id; char name[200]; enum frm_cuda_function_arg_kind_t kind; enum frm_cuda_mem_scope_t mem_scope; enum frm_cuda_function_arg_access_type_t access_type; unsigned int value; }


decompiled_code:
__int64 __fastcall frm_cuda_function_arg_free(__int64 a1)
{
return mhandle_free(a1, "cuda-obj.c:291");
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return mhandle_free(a1, "cuda-obj.c:291");
}

original_code:
void frm_cuda_function_arg_free(struct frm_cuda_function_arg_t *arg)
{
 (mhandle_free(arg, "cuda-obj.c" ":" "291"));
}

user_defined_types: enum frm_cuda_function_arg_kind_t { FRM_CUDA_FUNCTION_ARG_KIND_VALUE=1, FRM_CUDA_FUNCTION_ARG_KIND_POINTER=2 }

user_defined_types: enum frm_cuda_mem_scope_t { FRM_CUDA_MEM_SCOPE_NONE=0, FRM_CUDA_MEM_SCOPE_GLOBAL=1, FRM_CUDA_MEM_SCOPE_LOCAL=2, FRM_CUDA_MEM_SCOPE_PRIVATE=3, FRM_CUDA_MEM_SCOPE_CONSTANT=4 }

user_defined_types: enum frm_cuda_function_arg_access_type_t { FRM_CUDA_FUNCTION_ARG_READ_ONLY=1, FRM_CUDA_FUNCTION_ARG_WRITE_ONLY=2, FRM_CUDA_FUNCTION_ARG_READ_WRITE=3 }


decompiled_code:
_DWORD *frm_cuda_memory_create()
{
_DWORD *v0; // rbx

v0 = (_DWORD *)mhandle_calloc(1LL, 20LL, "cuda-obj.c:349");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_memory_create");
*v0 = frm_cuda_object_new_id(5);
v0[1] = 1;
frm_cuda_object_add((__int64)v0);
return v0;
}

canonical_decompiled_code:
_DWORD *func13()
{
_DWORD *v0; // rbx

v0 = (_DWORD *)mhandle_calloc(1LL, 20LL, "cuda-obj.c:349");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_memory_create");
*v0 = func2(5);
v0[1] = 1;
func0((__int64)v0);
return v0;
}

original_code:
struct frm_cuda_memory_t *frm_cuda_memory_create()
{
        struct frm_cuda_memory_t *mem;
        mem = (mhandle_calloc(1, sizeof(struct frm_cuda_memory_t), "cuda-obj.c" ":" "349"));
        if (!mem)
                fatal("%s: out of memory", __FUNCTION__);
        mem->id = frm_cuda_object_new_id(FRM_CUDA_OBJ_MEMORY);
        mem->ref_count = 1;
        frm_cuda_object_add(mem);
        return mem;
}

variable_types: struct frm_cuda_memory_t { unsigned int id; int ref_count; unsigned int size; unsigned int host_ptr; unsigned int device_ptr; } *


decompiled_code:
__int64 __fastcall frm_cuda_memory_free(__int64 a1)
{
frm_cuda_object_remove(a1);
return mhandle_free(a1, "cuda-obj.c:366");
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
func1(a1);
return mhandle_free(a1, "cuda-obj.c:366");
}

original_code:
void frm_cuda_memory_free(struct frm_cuda_memory_t *mem)
{
        frm_cuda_object_remove(mem);
        (mhandle_free(mem, "cuda-obj.c" ":" "366"));
}

user_defined_types: struct frm_cuda_memory_t { unsigned int id; int ref_count; unsigned int size; unsigned int host_ptr; unsigned int device_ptr; }


decompiled_code:
_DWORD *frm_cuda_stream_create()
{
_DWORD *v0; // rbx

v0 = (_DWORD *)mhandle_calloc(1LL, 16LL, "cuda-obj.c:383");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_stream_create");
*v0 = frm_cuda_object_new_id(6);
v0[1] = 1;
frm_cuda_object_add((__int64)v0);
return v0;
}

canonical_decompiled_code:
_DWORD *func15()
{
_DWORD *v0; // rbx

v0 = (_DWORD *)mhandle_calloc(1LL, 16LL, "cuda-obj.c:383");
if ( !v0 )
fatal("%s: out of memory", "frm_cuda_stream_create");
*v0 = func2(6);
v0[1] = 1;
func0((__int64)v0);
return v0;
}

original_code:
struct frm_cuda_stream_t *frm_cuda_stream_create()
{
 struct frm_cuda_stream_t *stream;
 stream = (mhandle_calloc(1, sizeof(struct frm_cuda_stream_t), "cuda-obj.c" ":" "383"));
 if (!stream)
  fatal("%s: out of memory", __FUNCTION__);
 stream->id = frm_cuda_object_new_id(FRM_CUDA_OBJ_STREAM);
 stream->ref_count = 1;
 frm_cuda_object_add(stream);
 return stream;
}

variable_types: struct frm_cuda_stream_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; } *


decompiled_code:
__int64 __fastcall frm_cuda_stream_free(__int64 a1)
{
frm_cuda_object_remove(a1);
return mhandle_free(a1, "cuda-obj.c:402");
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
func1(a1);
return mhandle_free(a1, "cuda-obj.c:402");
}

original_code:
void frm_cuda_stream_free(struct frm_cuda_stream_t *stream)
{
 frm_cuda_object_remove(stream);
 (mhandle_free(stream, "cuda-obj.c" ":" "402"));
}

user_defined_types: struct frm_cuda_stream_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; }


decompiled_code:
_QWORD *si_opencl_repo_create()
{
_QWORD *v0; // rbx

v0 = (_QWORD *)mhandle_calloc(1LL, 8LL, "opencl-repo.c:40");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_repo_create");
*v0 = linked_list_create();
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rbx

v0 = (_QWORD *)mhandle_calloc(1LL, 8LL, "opencl-repo.c:40");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_repo_create");
*v0 = linked_list_create();
return v0;
}

original_code:
struct si_opencl_repo_t *si_opencl_repo_create(void)
{
 struct si_opencl_repo_t *repo;
 repo = (mhandle_calloc(1, sizeof(struct si_opencl_repo_t), "opencl-repo.c" ":" "40"));
 if (!repo)
  fatal("%s: out of memory", __FUNCTION__);
 repo->object_list = linked_list_create();
 return repo;
}

canonical_original_code:
struct si_opencl_repo_t *si_opencl_repo_create()
{
 struct si_opencl_repo_t *repo;
 repo = (mhandle_calloc(1, sizeof(struct si_opencl_repo_t), "opencl-repo.c" ":" "40"));
 if (!repo)
  fatal("%s: out of memory", __FUNCTION__);
 repo->object_list = linked_list_create();
 return repo;
}

variable_types: struct si_opencl_repo_t { struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *object_list; } *

user_defined_types: struct si_opencl_repo_t { struct linked_list_t *object_list; }

user_defined_types: struct linked_list_t { int count; int error_code; struct linked_list_elem_t *head; int current_index; }


decompiled_code:
__int64 __fastcall si_opencl_repo_free(_QWORD *a1)
{
linked_list_free(*a1);
return mhandle_free(a1, "opencl-repo.c:55");
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
linked_list_free(*a1);
return mhandle_free(a1, "opencl-repo.c:55");
}

original_code:
void si_opencl_repo_free(struct si_opencl_repo_t *repo)
{
 linked_list_free(repo->object_list);
 (mhandle_free(repo, "opencl-repo.c" ":" "55"));
}

user_defined_types: struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; }


decompiled_code:
__int64 __fastcall si_opencl_repo_add_object(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbp

v2 = *a1;
linked_list_find(*a1);
if ( !*(_DWORD *)(v2 + 4) )
fatal("%s: object already exists", "si_opencl_repo_add_object");
return linked_list_add(v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
__int64 v2; // rbp

v2 = *a1;
linked_list_find(*a1);
if ( !*(_DWORD *)(v2 + 4) )
fatal("%s: object already exists", "si_opencl_repo_add_object");
return linked_list_add(v2, a2);
}

original_code:
void si_opencl_repo_add_object(struct si_opencl_repo_t *repo,
 void *object)
{
 struct linked_list_t *object_list = repo->object_list;
 linked_list_find(object_list, object);
 if (!object_list->error_code)
  fatal("%s: object already exists", __FUNCTION__);
 linked_list_add(object_list, object);
}

variable_types: struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *


decompiled_code:
__int64 __fastcall si_opencl_repo_remove_object(_QWORD *a1)
{
__int64 v1; // rbx

v1 = *a1;
linked_list_find(*a1);
if ( *(_DWORD *)(v1 + 4) )
fatal("%s: object does not exist", "si_opencl_repo_remove_object");
return linked_list_remove(v1);
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 v1; // rbx

v1 = *a1;
linked_list_find(*a1);
if ( *(_DWORD *)(v1 + 4) )
fatal("%s: object does not exist", "si_opencl_repo_remove_object");
return linked_list_remove(v1);
}

original_code:
void si_opencl_repo_remove_object(struct si_opencl_repo_t *repo,
 void *object)
{
 struct linked_list_t *object_list = repo->object_list;
 linked_list_find(object_list, object);
 if (object_list->error_code)
  fatal("%s: object does not exist", __FUNCTION__);
 linked_list_remove(object_list);
}


decompiled_code:
__int64 __fastcall si_opencl_repo_new_object_id(__int64 a1, int a2)
{
unsigned int v2; // ebx

v2 = si_opencl_object_id_counter_2++ | (a2 << 16);
if ( (unsigned int)si_opencl_object_id_counter_2 > 0xFFFF )
fatal("%s: limit of OpenCL objects exceeded\n", "si_opencl_repo_new_object_id");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
unsigned int v2; // ebx

v2 = si_opencl_object_id_counter_2++ | (a2 << 16);
if ( (unsigned int)si_opencl_object_id_counter_2 > 0xFFFF )
fatal("%s: limit of OpenCL objects exceeded\n", "si_opencl_repo_new_object_id");
return v2;
}

original_code:
unsigned int si_opencl_repo_new_object_id(struct si_opencl_repo_t *repo,
 enum si_opencl_object_type_t type)
{
 static unsigned int si_opencl_object_id_counter;
 unsigned int object_id;
 object_id = (type << 16) | si_opencl_object_id_counter;
 si_opencl_object_id_counter++;
 if (si_opencl_object_id_counter > 0xffff)
  fatal("%s: limit of OpenCL objects exceeded\n", __FUNCTION__);
 return object_id;
}

variable_types: enum si_opencl_object_type_t { si_opencl_object_invalid=0, si_opencl_object_platform=1, si_opencl_object_device=2, si_opencl_object_context=3, si_opencl_object_command_queue=4, si_opencl_object_program=5, si_opencl_object_kernel=6, si_opencl_object_mem=7, si_opencl_object_event=8, si_opencl_object_sampler=9 }


decompiled_code:
__int64 __fastcall file_desc_free(__int64 a1)
{
__int64 v2; // rdi

v2 = *(_QWORD *)(a1 + 16);
if ( v2 )
mhandle_free(v2, "file.c:59");
return mhandle_free(a1, "file.c:60");
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v2; // rdi

v2 = *(_QWORD *)(a1 + 16);
if ( v2 )
mhandle_free(v2, "file.c:59");
return mhandle_free(a1, "file.c:60");
}

original_code:
static void file_desc_free(struct file_desc_t *desc)
{
 if (desc->path)
  (mhandle_free(desc->path, "file.c" ":" "59"));
 (mhandle_free(desc, "file.c" ":" "60"));
}

variable_types: struct file_desc_t { enum file_desc_kind_t { file_desc_invalid=0, file_desc_regular=1, file_desc_std=2, file_desc_pipe=3, file_desc_virtual=4, file_desc_gpu=5, file_desc_socket=6 } kind; int guest_fd; int host_fd; int flags; char *path; } *

user_defined_types: struct file_desc_t { enum file_desc_kind_t kind; int guest_fd; int host_fd; int flags; char *path; }


decompiled_code:
__int64 __fastcall file_desc_create(int a1, int a2, int a3, int a4, __int64 a5)
{
__int64 v8; // rbx
__int64 v9; // rax

v8 = mhandle_calloc(1LL, 24LL, "file.c:33");
if ( !v8 )
fatal("%s: out of memory", "file_desc_create");
*(_DWORD *)v8 = a1;
*(_DWORD *)(v8 + 4) = a2;
*(_DWORD *)(v8 + 8) = a3;
*(_DWORD *)(v8 + 12) = a4;
if ( a5 )
{
v9 = mhandle_strdup(a5, "file.c:46");
*(_QWORD *)(v8 + 16) = v9;
if ( !v9 )
fatal("%s: out of memory", "file_desc_create");
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3, int a4, __int64 a5)
{
__int64 v8; // rbx
__int64 v9; // rax

v8 = mhandle_calloc(1LL, 24LL, "file.c:33");
if ( !v8 )
fatal("%s: out of memory", "file_desc_create");
*(_DWORD *)v8 = a1;
*(_DWORD *)(v8 + 4) = a2;
*(_DWORD *)(v8 + 8) = a3;
*(_DWORD *)(v8 + 12) = a4;
if ( a5 )
{
v9 = mhandle_strdup(a5, "file.c:46");
*(_QWORD *)(v8 + 16) = v9;
if ( !v9 )
fatal("%s: out of memory", "file_desc_create");
}
return v8;
}

original_code:
struct file_desc_t *file_desc_create(enum file_desc_kind_t kind,
 int guest_fd, int host_fd, int flags, char *path)
{
 struct file_desc_t *desc;
 desc = (mhandle_calloc(1, sizeof(struct file_desc_t), "file.c" ":" "33"));
 if (!desc)
  fatal("%s: out of memory", __FUNCTION__);
 desc->kind = kind;
 desc->guest_fd = guest_fd;
 desc->host_fd = host_fd;
 desc->flags = flags;
 if (path)
 {
  desc->path = (mhandle_strdup(path, "file.c" ":" "46"));
  if (!desc->path)
   fatal("%s: out of memory", __FUNCTION__);
 }
 return desc;
}

variable_types: flags int

variable_types:
path
char *

return_type: struct file_desc_t { enum file_desc_kind_t { file_desc_invalid=0, file_desc_regular=1, file_desc_std=2, file_desc_pipe=3, file_desc_virtual=4, file_desc_gpu=5, file_desc_socket=6 } kind; int guest_fd; int host_fd; int flags; char *path; } *


decompiled_code:
__int64 file_desc_table_create()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax

v0 = mhandle_calloc(1LL, 16LL, "file.c:76");
if ( !v0 )
fatal("%s: out of memory", "file_desc_table_create");
*(_QWORD *)(v0 + 8) = list_create();
v1 = file_desc_create(2, 0, 0, 0, 0LL);
list_add(*(_QWORD *)(v0 + 8), v1);
v2 = file_desc_create(2, 1, 1, 0, 0LL);
list_add(*(_QWORD *)(v0 + 8), v2);
v3 = file_desc_create(2, 2, 2, 0, 0LL);
list_add(*(_QWORD *)(v0 + 8), v3);
return v0;
}

original_code:
struct file_desc_table_t *file_desc_table_create(void)
{
 struct file_desc_table_t *table;
 struct file_desc_t *desc;
 table = (mhandle_calloc(1, sizeof(struct file_desc_table_t), "file.c" ":" "76"));
 if (!table)
  fatal("%s: out of memory", __FUNCTION__);
 table->file_desc_list = list_create();
 desc = file_desc_create(file_desc_std, 0, 0, 0, ((void *)0));
 list_add(table->file_desc_list, desc);
 desc = file_desc_create(file_desc_std, 1, 1, 0, ((void *)0));
 list_add(table->file_desc_list, desc);
 desc = file_desc_create(file_desc_std, 2, 2, 0, ((void *)0));
 list_add(table->file_desc_list, desc);
 return table;
}

canonical_original_code:
struct file_desc_table_t *file_desc_table_create()
{
 struct file_desc_table_t *table;
 struct file_desc_t *desc;
 table = (mhandle_calloc(1, sizeof(struct file_desc_table_t), "file.c" ":" "76"));
 if (!table)
  fatal("%s: out of memory", __FUNCTION__);
 table->file_desc_list = list_create();
 desc = file_desc_create(file_desc_std, 0, 0, 0, ((void *)0));
 list_add(table->file_desc_list, desc);
 desc = file_desc_create(file_desc_std, 1, 1, 0, ((void *)0));
 list_add(table->file_desc_list, desc);
 desc = file_desc_create(file_desc_std, 2, 2, 0, ((void *)0));
 list_add(table->file_desc_list, desc);
 return table;
}

variable_types: struct file_desc_table_t { int num_links; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *file_desc_list; } *

user_defined_types: struct file_desc_table_t { int num_links; struct list_t *file_desc_list; }

user_defined_types: enum file_desc_kind_t { file_desc_invalid=0, file_desc_regular=1, file_desc_std=2, file_desc_pipe=3, file_desc_virtual=4, file_desc_gpu=5, file_desc_socket=6 }


decompiled_code:
__int64 __fastcall file_desc_table_free(__int64 a1)
{
int v1; // ebx
__int64 v2; // rax

v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
_assert_fail("!table->num_links", "file.c", 0x6Au, "file_desc_table_free");
while ( (int)list_count(*(_QWORD *)(a1 + 8)) > v1 )
{
v2 = list_get(*(_QWORD *)(a1 + 8), (unsigned int)v1);
if ( v2 )
file_desc_free(v2);
++v1;
}
list_free(*(_QWORD *)(a1 + 8));
return mhandle_free(a1, "file.c:118");
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // ebx
__int64 v2; // rax

v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 )
_assert_fail("!table->num_links", "file.c", 0x6Au, "file_desc_table_free");
while ( (int)list_count(*(_QWORD *)(a1 + 8)) > v1 )
{
v2 = list_get(*(_QWORD *)(a1 + 8), (unsigned int)v1);
if ( v2 )
func0(v2);
++v1;
}
list_free(*(_QWORD *)(a1 + 8));
return mhandle_free(a1, "file.c:118");
}

original_code:
void file_desc_table_free(struct file_desc_table_t *table)
{
 int i;
 struct file_desc_t *desc;
 ((void) sizeof ((!table->num_links) ? 1 : 0), __extension__ ({ if (!table->num_links) ; else __assert_fail ("!table->num_links", "file.c", 106, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < list_count(table->file_desc_list); i++)
 {
  desc = list_get(table->file_desc_list, i);
  if (desc)
   file_desc_free(desc);
 }
 list_free(table->file_desc_list);
 (mhandle_free(table, "file.c" ":" "118"));
}

variable_types: i int


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

v1 = *a1;
if ( *a1 < 0 )
_assert_fail("fdt->num_links >= 0", "file.c", 0x83u, "file_desc_table_unlink");
if ( !v1 )
return file_desc_table_free((__int64)a1);
result = (unsigned int)(v1 - 1);
*a1 = result;
return result;
}

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

v1 = *a1;
if ( *a1 < 0 )
_assert_fail("fdt->num_links >= 0", "file.c", 0x83u, "file_desc_table_unlink");
if ( !v1 )
return func3((__int64)a1);
result = (unsigned int)(v1 - 1);
*a1 = result;
return result;
}

original_code:
void file_desc_table_unlink(struct file_desc_table_t *fdt)
{
 ((void) sizeof ((fdt->num_links >= 0) ? 1 : 0), __extension__ ({ if (fdt->num_links >= 0) ; else __assert_fail ("fdt->num_links >= 0", "file.c", 131, __extension__ __PRETTY_FUNCTION__); }));
 if (fdt->num_links)
  fdt->num_links--;
 else
  file_desc_table_free(fdt);
}


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

v2 = list_get(*(_QWORD *)(a1 + 8), a2);
if ( v2 )
result = *(unsigned int *)(v2 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

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

v2 = list_get(*(_QWORD *)(a1 + 8), a2);
if ( v2 )
result = *(unsigned int *)(v2 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int file_desc_table_get_host_fd(struct file_desc_table_t *table, int guest_fd)
{
 struct file_desc_t *desc;
 desc = list_get(table->file_desc_list, guest_fd);
 return desc ? desc->host_fd : -1;
}


decompiled_code:
__int64 __fastcall file_desc_table_get_guest_fd(__int64 a1, int a2)
{
unsigned int i; // ebx

for ( i = 0; (int)list_count(*(_QWORD *)(a1 + 8)) > (int)i; ++i )
{
if ( *(_DWORD *)(list_get(*(_QWORD *)(a1 + 8), i) + 8) == a2 )
return i;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
unsigned int i; // ebx

for ( i = 0; (int)list_count(*(_QWORD *)(a1 + 8)) > (int)i; ++i )
{
if ( *(_DWORD *)(list_get(*(_QWORD *)(a1 + 8), i) + 8) == a2 )
return i;
}
return (unsigned int)-1;
}

original_code:
int file_desc_table_get_guest_fd(struct file_desc_table_t *table, int host_fd)
{
 struct file_desc_t *desc;
 int i;
 for (i = 0; i < list_count(table->file_desc_list); i++)
 {
  desc = list_get(table->file_desc_list, i);
  if (desc->host_fd == host_fd)
   return i;
 }
 return -1;
}


decompiled_code:
__int64 __fastcall file_desc_table_entry_get(__int64 a1, __int64 a2)
{
return list_get(*(_QWORD *)(a1 + 8), a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
return list_get(*(_QWORD *)(a1 + 8), a2);
}

original_code:
struct file_desc_t *file_desc_table_entry_get(struct file_desc_table_t *table, int index)
{
 return list_get(table->file_desc_list, index);
}

variable_types: index int


decompiled_code:
__int64 __fastcall file_desc_table_entry_new_guest_fd(__int64 a1, int a2, int a3, int a4, __int64 a5, int a6)
{
int i; // ebx
int v11; // eax
int j; // ebx
__int64 v13; // rbx

for ( i = 0; ; ++i )
{
v11 = list_count(*(_QWORD *)(a1 + 8));
if ( a3 >= 0 || v11 <= i )
break;
if ( !list_get(*(_QWORD *)(a1 + 8), (unsigned int)i) )
a3 = i;
}
if ( a3 < 0 )
{
a3 = list_count(*(_QWORD *)(a1 + 8));
list_add(*(_QWORD *)(a1 + 8), 0LL);
}
for ( j = list_count(*(_QWORD *)(a1 + 8)); a3 >= j; ++j )
list_add(*(_QWORD *)(a1 + 8), 0LL);
v13 = file_desc_create(a2, a3, a4, a6, a5);
list_set(*(_QWORD *)(a1 + 8), (unsigned int)a3, v13);
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, int a3, int a4, __int64 a5, int a6)
{
int i; // ebx
int v11; // eax
int j; // ebx
__int64 v13; // rbx

for ( i = 0; ; ++i )
{
v11 = list_count(*(_QWORD *)(a1 + 8));
if ( a3 >= 0 || v11 <= i )
break;
if ( !list_get(*(_QWORD *)(a1 + 8), (unsigned int)i) )
a3 = i;
}
if ( a3 < 0 )
{
a3 = list_count(*(_QWORD *)(a1 + 8));
list_add(*(_QWORD *)(a1 + 8), 0LL);
}
for ( j = list_count(*(_QWORD *)(a1 + 8)); a3 >= j; ++j )
list_add(*(_QWORD *)(a1 + 8), 0LL);
v13 = func1(a2, a3, a4, a6, a5);
list_set(*(_QWORD *)(a1 + 8), (unsigned int)a3, v13);
return v13;
}

original_code:
struct file_desc_t *file_desc_table_entry_new_guest_fd(struct file_desc_table_t *table,
 enum file_desc_kind_t kind, int guest_fd, int host_fd, char *path, int flags)
{
 struct file_desc_t *desc;
 int i;
 for (i = 0; i < list_count(table->file_desc_list) && guest_fd < 0; i++)
  if (!list_get(table->file_desc_list, i))
   guest_fd = i;
 if (guest_fd < 0)
 {
  guest_fd = list_count(table->file_desc_list);
  list_add(table->file_desc_list, ((void *)0));
 }
 for (i = list_count(table->file_desc_list); i <= guest_fd; ++i) {
  list_add(table->file_desc_list, ((void *)0));
 }
 desc = file_desc_create(kind, guest_fd, host_fd, flags, path);
 list_set(table->file_desc_list, guest_fd, desc);
 return desc;
}

variable_types: enum file_desc_kind_t { file_desc_invalid=0, file_desc_regular=1, file_desc_std=2, file_desc_pipe=3, file_desc_virtual=4, file_desc_gpu=5, file_desc_socket=6 }


decompiled_code:
__int64 __fastcall file_desc_table_entry_new(__int64 a1, int a2, int a3, __int64 a4, int a5)
{
return file_desc_table_entry_new_guest_fd(a1, a2, -1, a3, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2, int a3, __int64 a4, int a5)
{
return func10(a1, a2, -1, a3, a4, a5);
}

original_code:
struct file_desc_t *file_desc_table_entry_new(struct file_desc_table_t *table,
 enum file_desc_kind_t kind, int host_fd, char *path, int flags)
{
 return file_desc_table_entry_new_guest_fd(table, kind, -1, host_fd, path, flags);
}


decompiled_code:
__int64 __fastcall file_desc_table_entry_free(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbx

result = list_get(*(_QWORD *)(a1 + 8), a2);
if ( result )
{
v3 = result;
if ( *(_DWORD *)result == 4 )
{
if ( unlink(*(const char **)(result + 16)) )
warning("%s: temporary host virtual file could not be deleted", *(const char **)(v3 + 16));
}
list_set(*(_QWORD *)(a1 + 8), (unsigned int)a2, 0LL);
result = file_desc_free(v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbx

result = list_get(*(_QWORD *)(a1 + 8), a2);
if ( result )
{
v3 = result;
if ( *(_DWORD *)result == 4 )
{
if ( unlink(*(const char **)(result + 16)) )
warning("%s: temporary host virtual file could not be deleted", *(const char **)(v3 + 16));
}
list_set(*(_QWORD *)(a1 + 8), (unsigned int)a2, 0LL);
result = func0(v3);
}
return result;
}

original_code:
void file_desc_table_entry_free(struct file_desc_table_t *table, int index)
{
 struct file_desc_t *desc;
 desc = list_get(table->file_desc_list, index);
 if (!desc)
  return;
 if (desc->kind == file_desc_virtual)
 {
  if (unlink(desc->path))
   warning("%s: temporary host virtual file could not be deleted",
    desc->path);
 }
 list_set(table->file_desc_list, index, ((void *)0));
 file_desc_free(desc);
}


decompiled_code:
__int64 __fastcall arm_file_desc_free(__int64 a1)
{
__int64 v2; // rdi

v2 = *(_QWORD *)(a1 + 16);
if ( v2 )
mhandle_free(v2, "file.c:59");
return mhandle_free(a1, "file.c:60");
}

original_code:
static void arm_file_desc_free(struct arm_file_desc_t *desc)
{
 if (desc->path)
  (mhandle_free(desc->path, "file.c" ":" "59"));
 (mhandle_free(desc, "file.c" ":" "60"));
}

variable_types: struct arm_file_desc_t { enum arm_file_desc_kind_t { arm_file_desc_invalid=0, arm_file_desc_regular=1, arm_file_desc_std=2, arm_file_desc_pipe=3, arm_file_desc_virtual=4, arm_file_desc_gpu=5, arm_file_desc_socket=6 } kind; int guest_fd; int host_fd; int flags; char *path; } *

user_defined_types: struct arm_file_desc_t { enum arm_file_desc_kind_t kind; int guest_fd; int host_fd; int flags; char *path; }


decompiled_code:
__int64 __fastcall arm_file_desc_create(int a1, int a2, int a3, int a4, __int64 a5)
{
__int64 v8; // rbx
__int64 v9; // rax

v8 = mhandle_calloc(1LL, 24LL, "file.c:33");
if ( !v8 )
fatal("%s: out of memory", "arm_file_desc_create");
*(_DWORD *)v8 = a1;
*(_DWORD *)(v8 + 4) = a2;
*(_DWORD *)(v8 + 8) = a3;
*(_DWORD *)(v8 + 12) = a4;
if ( a5 )
{
v9 = mhandle_strdup(a5, "file.c:46");
*(_QWORD *)(v8 + 16) = v9;
if ( !v9 )
fatal("%s: out of memory", "arm_file_desc_create");
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3, int a4, __int64 a5)
{
__int64 v8; // rbx
__int64 v9; // rax

v8 = mhandle_calloc(1LL, 24LL, "file.c:33");
if ( !v8 )
fatal("%s: out of memory", "arm_file_desc_create");
*(_DWORD *)v8 = a1;
*(_DWORD *)(v8 + 4) = a2;
*(_DWORD *)(v8 + 8) = a3;
*(_DWORD *)(v8 + 12) = a4;
if ( a5 )
{
v9 = mhandle_strdup(a5, "file.c:46");
*(_QWORD *)(v8 + 16) = v9;
if ( !v9 )
fatal("%s: out of memory", "arm_file_desc_create");
}
return v8;
}

original_code:
struct arm_file_desc_t *arm_file_desc_create(enum arm_file_desc_kind_t kind,
 int guest_fd, int host_fd, int flags, char *path)
{
 struct arm_file_desc_t *desc;
 desc = (mhandle_calloc(1, sizeof(struct arm_file_desc_t), "file.c" ":" "33"));
 if (!desc)
  fatal("%s: out of memory", __FUNCTION__);
 desc->kind = kind;
 desc->guest_fd = guest_fd;
 desc->host_fd = host_fd;
 desc->flags = flags;
 if (path)
 {
  desc->path = (mhandle_strdup(path, "file.c" ":" "46"));
  if (!desc->path)
   fatal("%s: out of memory", __FUNCTION__);
 }
 return desc;
}

return_type: struct arm_file_desc_t { enum arm_file_desc_kind_t { arm_file_desc_invalid=0, arm_file_desc_regular=1, arm_file_desc_std=2, arm_file_desc_pipe=3, arm_file_desc_virtual=4, arm_file_desc_gpu=5, arm_file_desc_socket=6 } kind; int guest_fd; int host_fd; int flags; char *path; } *