original_code:
double diffPlaneToParallelRect1(double a, double b, double c)
{
  double A = a/c;
  double B = b/c;
  double rA,rB;
  rA = 1.0/sqrt(1.0+A*A);
  rB = 1.0/sqrt(1.0+B*B);
  return 0.5*(A*atan(B*rA)*rA + B*atan(A*rB)*rB)/3.14159265358979323846;
}

canonical_original_code:
double diffPlaneToParallelRect1(double a, double b, double c)
{
  double A = a/c;
  double B = b/c;
  double rA; double rB;
  rA = 1.0/sqrt(1.0+A*A);
  rB = 1.0/sqrt(1.0+B*B);
  return 0.5*(A*atan(B*rA)*rA + B*atan(A*rB)*rB)/3.14159265358979323846;
}


diffPlaneToFiniteCyl

repo: jasondegraw/ViewFactors

original_code:
double diffPlaneToFiniteCyl(double L, double H)
{
  double Hm1 = H-1.0;
  double Hp1 = H+1.0;
  double X = Hp1*Hp1 + L*L;
  double Y = Hm1*Hm1 + L*L;
  return (atan(L/sqrt(Hp1*Hm1))/H
      + L*((X-2.0*H)*atan(sqrt(X*Hm1/(Y*Hp1)))/(H*sqrt(X*Y))
           - atan(sqrt(Hm1/Hp1))/H))/3.14159265358979323846;
}

variable_types: L double

variable_types: H double

variable_types: X double

variable_types: Y double

return_type: double


original_code:
double diffPlaneToFiniteCyl1(double r, double l, double h)
{
  double L = l/r;
  double H = h/r;
  double Hm1 = H-1.0;
  double Hp1 = H+1.0;
  double X = Hp1*Hp1 + L*L;
  double Y = Hm1*Hm1 + L*L;
  return (atan(L/sqrt(Hp1*Hm1))/H
      + L*((X-2.0*H)*atan(sqrt(X*Hm1/(Y*Hp1)))/(H*sqrt(X*Y))
           - atan(sqrt(Hm1/Hp1))/H))/3.14159265358979323846;
}

variable_types: r double

variable_types: l double

variable_types: h double


repo: jasonluther/pi-rgb

decompiled_code:
void *__fastcall open_rgbcmd(int a1)
{
int v1; // ebx
void *v2; // rbp
int *v4; // rbx
char *v5; // rax
int *v6; // rbx
char *v7; // rax
int *v8; // rbx
char *v9; // rax
int v10; // eax
int *v11; // rbx
char *v12; // rax

if ( !a1 )
{
v1 = open("/var/rgbcmd", 2);
if ( v1 >= 0 )
goto LABEL_3;
LABEL_5:
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "Unable to open /var/rgbcmd: %s\n", v5);
exit(*v4);
}
v10 = open("/var/rgbcmd", 578);
v1 = v10;
if ( v10 < 0 )
goto LABEL_5;
if ( (int)lseek(v10, 8LL, 0) < 0 )
{
close(v1);
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Unable to lseek /var/rgbcmd: %s\n", v7);
exit(*v6);
}
if ( (unsigned int)write(v1, &unk_2C4, 1uLL) != 1 )
{
close(v1);
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "Unable to write to /var/rgbcmd: %s\n", v12);
exit(*v11);
}
LABEL_3:
v2 = mmap(0LL, 8uLL, 3, 1, v1, 0LL);
if ( v2 == (void *)-1LL )
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(stderr, "Unable to mmap /var/rgbcmd: %s\n", v9);
exit(*v8);
}
close(v1);
return v2;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
int v1; // ebx
void *v2; // rbp
int *v4; // rbx
char *v5; // rax
int *v6; // rbx
char *v7; // rax
int *v8; // rbx
char *v9; // rax
int v10; // eax
int *v11; // rbx
char *v12; // rax

if ( !a1 )
{
v1 = open("/var/rgbcmd", 2);
if ( v1 >= 0 )
goto LABEL_3;
LABEL_5:
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "Unable to open /var/rgbcmd: %s\n", v5);
exit(*v4);
}
v10 = open("/var/rgbcmd", 578);
v1 = v10;
if ( v10 < 0 )
goto LABEL_5;
if ( (int)lseek(v10, 8LL, 0) < 0 )
{
close(v1);
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Unable to lseek /var/rgbcmd: %s\n", v7);
exit(*v6);
}
if ( (unsigned int)write(v1, &unk_2C4, 1uLL) != 1 )
{
close(v1);
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "Unable to write to /var/rgbcmd: %s\n", v12);
exit(*v11);
}
LABEL_3:
v2 = mmap(0LL, 8uLL, 3, 1, v1, 0LL);
if ( v2 == (void *)-1LL )
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(stderr, "Unable to mmap /var/rgbcmd: %s\n", v9);
exit(*v8);
}
close(v1);
return v2;
}

original_code:
rgbcmd_t *open_rgbcmd(int need_to_create) {
  rgbcmd_t *cmd;
  int fd, result;
  int openargs, mmapflags;
  mmapflags = 0x1|0x2;
  if (need_to_create) {
    openargs = 0100|01000|02;
  } else {
    openargs = 02;
  }
  if ((fd = open("/var/rgbcmd", openargs)) < 0) {
    fprintf(stderr, "Unable to open /var/rgbcmd: %s\n", strerror((*__errno_location ())));
    exit((*__errno_location ()));
  }
  if (need_to_create) {
    if ((result = lseek(fd, sizeof(rgbcmd_t), 0)) < 0) {
      close(fd);
      fprintf(stderr, "Unable to lseek /var/rgbcmd: %s\n", strerror((*__errno_location ())));
      exit((*__errno_location ()));
    }
    if ((result = write(fd, "", 1)) != 1) {
      close(fd);
      fprintf(stderr, "Unable to write to /var/rgbcmd: %s\n", strerror((*__errno_location ())));
      exit((*__errno_location ()));
    }
  }
  cmd = mmap(((void *)0), sizeof(rgbcmd_t), mmapflags, 0x01|0, fd, 0);
  if (cmd == ((void *) -1)) {
    fprintf(stderr, "Unable to mmap /var/rgbcmd: %s\n", strerror((*__errno_location ())));
    exit((*__errno_location ()));
  }
  close(fd);
  return cmd;
}

canonical_original_code:
struct rgbcmd *open_rgbcmd(int need_to_create) {
  struct rgbcmd *cmd;
  int fd; int result;
  int openargs; int mmapflags;
  mmapflags = 0x1|0x2;
  if (need_to_create) {
    openargs = 0100|01000|02;
  } else {
    openargs = 02;
  }
  if ((fd = open("/var/rgbcmd", openargs)) < 0) {
    fprintf(stderr, "Unable to open /var/rgbcmd: %s\n", strerror((*__errno_location ())));
    exit((*__errno_location ()));
  }
  if (need_to_create) {
    if ((result = lseek(fd, sizeof(rgbcmd_t), 0)) < 0) {
      close(fd);
      fprintf(stderr, "Unable to lseek /var/rgbcmd: %s\n", strerror((*__errno_location ())));
      exit((*__errno_location ()));
    }
    if ((result = write(fd, "", 1)) != 1) {
      close(fd);
      fprintf(stderr, "Unable to write to /var/rgbcmd: %s\n", strerror((*__errno_location ())));
      exit((*__errno_location ()));
    }
  }
  cmd = mmap(((void *)0), sizeof(rgbcmd_t), mmapflags, 0x01|0, fd, 0);
  if (cmd == ((void *) -1)) {
    fprintf(stderr, "Unable to mmap /var/rgbcmd: %s\n", strerror((*__errno_location ())));
    exit((*__errno_location ()));
  }
  close(fd);
  return cmd;
}

variable_types: struct rgbcmd { enum rgbcmd_mode_t { RGB_MODE_ON=0, RGB_MODE_OFF=1, RGB_MODE_BLINK=2, RGB_MODE_RAINBOW=3, RGB_MODE_RANDOM=4 } mode; unsigned char red; unsigned char green; unsigned char blue; } *

variable_types: fd int

variable_types: result int

variable_types: openargs int

variable_types: mmapflags int

user_defined_types: struct rgbcmd { enum rgbcmd_mode_t mode; unsigned char red; unsigned char green; unsigned char blue; }


decompiled_code:
int __fastcall rgbcmd_json(__int64 a1, char *a2, size_t a3)
{
const char *v3; // rcx

switch ( *(_DWORD *)a1 )
{
case 0:
v3 = "on";
break;
case 1:
v3 = "off";
break;
case 2:
v3 = "blink";
break;
case 3:
v3 = "rainbow";
break;
case 4:
v3 = "random";
break;
default:
v3 = "unknown";
break;
}
return snprintf(
a2,
a3,
"{\"command\":\"%s\",\"red\":%d,\"green\":%d,\"blue\":%d,\"hex\":\"%02x%02x%02x\"}",
v3,
*(unsigned __int8 *)(a1 + 4),
*(unsigned __int8 *)(a1 + 5),
*(unsigned __int8 *)(a1 + 6),
*(unsigned __int8 *)(a1 + 4),
*(unsigned __int8 *)(a1 + 5),
*(unsigned __int8 *)(a1 + 6));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, char *a2, size_t a3)
{
const char *v3; // rcx

switch ( *(_DWORD *)a1 )
{
case 0:
v3 = "on";
break;
case 1:
v3 = "off";
break;
case 2:
v3 = "blink";
break;
case 3:
v3 = "rainbow";
break;
case 4:
v3 = "random";
break;
default:
v3 = "unknown";
break;
}
return snprintf(
a2,
a3,
"{\"command\":\"%s\",\"red\":%d,\"green\":%d,\"blue\":%d,\"hex\":\"%02x%02x%02x\"}",
v3,
*(unsigned __int8 *)(a1 + 4),
*(unsigned __int8 *)(a1 + 5),
*(unsigned __int8 *)(a1 + 6),
*(unsigned __int8 *)(a1 + 4),
*(unsigned __int8 *)(a1 + 5),
*(unsigned __int8 *)(a1 + 6));
}

original_code:
void rgbcmd_json(rgbcmd_t *cmd, char *buffer, size_t length) {
  char *modestring;
  switch(cmd->mode) {
    case RGB_MODE_ON:
      modestring = "on";
      break;
    case RGB_MODE_OFF:
      modestring = "off";
      break;
    case RGB_MODE_BLINK:
      modestring = "blink";
      break;
    case RGB_MODE_RAINBOW:
      modestring = "rainbow";
      break;
    case RGB_MODE_RANDOM:
      modestring = "random";
      break;
    default:
      modestring = "unknown";
  }
  snprintf(buffer, length,
    "{\"command\":\"%s\",\"red\":%d,\"green\":%d,\"blue\":%d,\"hex\":\"%02x%02x%02x\"}",
    modestring,
    cmd->red, cmd->green, cmd->blue,
    cmd->red, cmd->green, cmd->blue
  );
}

canonical_original_code:
void rgbcmd_json(struct rgbcmd *cmd, char *buffer, unsigned long length) {
  char *modestring;
  switch(cmd->mode) {
    case RGB_MODE_ON:
      modestring = "on";
      break;
    case RGB_MODE_OFF:
      modestring = "off";
      break;
    case RGB_MODE_BLINK:
      modestring = "blink";
      break;
    case RGB_MODE_RAINBOW:
      modestring = "rainbow";
      break;
    case RGB_MODE_RANDOM:
      modestring = "random";
      break;
    default:
      modestring = "unknown";
  }
  snprintf(buffer, length,
    "{\"command\":\"%s\",\"red\":%d,\"green\":%d,\"blue\":%d,\"hex\":\"%02x%02x%02x\"}",
    modestring,
    cmd->red, cmd->green, cmd->blue,
    cmd->red, cmd->green, cmd->blue
  );
}

variable_types:
buffer
char *

variable_types:
length
unsigned long

variable_types:
modestring
char *

return_type: void

user_defined_types: enum rgbcmd_mode_t { RGB_MODE_ON=0, RGB_MODE_OFF=1, RGB_MODE_BLINK=2, RGB_MODE_RAINBOW=3, RGB_MODE_RANDOM=4 }


acomalloc

decompiled_code:
void *__fastcall acomalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("Out of memory!\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
return result;
}

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

result = malloc(a1);
if ( !result )
{
fwrite("Out of memory!\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
return result;
}

original_code:
void *acomalloc(size_t len)
{
    void *ptr = malloc(len);
    if (ptr == ((void *)0)) {
        fprintf(stderr, "Out of memory!\n");
        exit(1);
    }
    return ptr;
}

canonical_original_code:
void *acomalloc(unsigned long len)
{
    void *ptr = malloc(len);
    if (ptr == ((void *)0)) {
        fprintf(stderr, "Out of memory!\n");
        exit(1);
    }
    return ptr;
}

variable_types:
len
unsigned long

variable_types:
ptr
void *

return_type: void *


genUIColors

original_code:
void genUIColors(struct aco *aco)
{
    int j;
    int cols = 4;
    for (j = 0; j < aco->len; j += cols) {
        int i;
        for (i = 0; i < cols; i++) {
            int r, g, b;
            char *class, *name;
            if (j+i == aco->len) break;
            r = aco->color[j+i].r;
            g = aco->color[j+i].g;
            b = aco->color[j+i].b;
            float rf = (float) r / 255;
            float gf = (float) g / 255;
            float bf = (float) b / 255;
            printf("[UIColor colorWithRed:%f green:%f blue:%f alpha:1.0f], // #%02x%02x%02x  rgb(%i,%i,%i) \n",
                   rf, gf, bf, r, g, b, r, g, b);
        }
    }
}

canonical_original_code:
void genUIColors(struct aco *aco)
{
    int j;
    int cols = 4;
    for (j = 0; j < aco->len; j += cols) {
        int i;
        for (i = 0; i < cols; i++) {
            int r; int g; int b;
            char *class; char *name;
            if (j+i == aco->len) break;
            r = aco->color[j+i].r;
            g = aco->color[j+i].g;
            b = aco->color[j+i].b;
            float rf = (float) r / 255;
            float gf = (float) g / 255;
            float bf = (float) b / 255;
            printf("[UIColor colorWithRed:%f green:%f blue:%f alpha:1.0f], // #%02x%02x%02x  rgb(%i,%i,%i) \n",
                   rf, gf, bf, r, g, b, r, g, b);
        }
    }
}

variable_types: struct aco { int ver; int len; struct acoentry { unsigned char r; char *name; } *color; } *

variable_types: j int

variable_types: cols int

variable_types: i int

variable_types: r int

variable_types: g int

variable_types: b int

variable_types:
class
char *

variable_types:
name
char *

variable_types: rf float

variable_types: gf float

variable_types: bf float

user_defined_types: struct aco { int ver; int len; struct acoentry *color; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbx

v3 = readaco(stdin);
fwrite("Read ACO : Generating UIColors (Hex & RGB Triplets @c77-85 & c86-)\n\n", 1uLL, 0x44uLL, stderr);
if ( v3 )
genUIColors((__int64)v3);
else
fwrite("No Colors found\n", 1uLL, 0x10uLL, stderr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbx

v3 = readaco(stdin);
fwrite("Read ACO : Generating UIColors (Hex & RGB Triplets @c77-85 & c86-)\n\n", 1uLL, 0x44uLL, stderr);
if ( v3 )
func10((__int64)v3);
else
fwrite("No Colors found\n", 1uLL, 0x10uLL, stderr);
return 0;
}

original_code:
int main(void)
{
    struct aco *aco;
    aco = readaco(stdin);
    fprintf(stderr, "Read ACO : Generating UIColors (Hex & RGB Triplets @c77-85 & c86-)\n\n");
    if(aco)
        genUIColors(aco);
    else
        fprintf(stderr, "No Colors found\n");
    return 0;
}

canonical_original_code:
int main()
{
    struct aco *aco;
    aco = readaco(stdin);
    fprintf(stderr, "Read ACO : Generating UIColors (Hex & RGB Triplets @c77-85 & c86-)\n\n");
    if(aco)
        genUIColors(aco);
    else
        fprintf(stderr, "No Colors found\n");
    return 0;
}

return_type: int

user_defined_types: struct acoentry { unsigned char r; char *name; }


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

if ( argc <= 1 )
{
sha_hash_file_output(0LL);
}
else
{
v3 = argv;
do
{
sha_hash_file_output((char *)v3[1]);
++v3;
}
while ( v3 != &argv[argc - 1] );
}
return 0;
}

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

if ( argc <= 1 )
{
func24(0LL);
}
else
{
v3 = argv;
do
{
func24((char *)v3[1]);
++v3;
}
while ( v3 != &argv[argc - 1] );
}
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
    if (argc > 1 ) {
        while (argc > 1) {
            sha_hash_file_output(argv[1]);
            argc--;
            argv++;
        }
    } else {
        sha_hash_file_output(((void *)0));
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall hexdump_char(unsigned __int8 a1, _BYTE *a2)
{
__int64 result; // rax

*a2 = byte_6A8[a1 >> 4];
result = (unsigned __int8)byte_6A8[a1 & 0xF];
a2[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, _BYTE *a2)
{
__int64 result; // rax

*a2 = byte_6A8[a1 >> 4];
result = (unsigned __int8)byte_6A8[a1 & 0xF];
a2[1] = result;
return result;
}

original_code:
static void
hexdump_char(uint8 c, char *str)
{
    static char *hex_digits = "0123456789abcdef";
    uint8 hi_nibble = (c >> 4);
    uint8 lo_nibble = c & 0x0F;
    *(str + 0) = *(hex_digits + hi_nibble);
    *(str + 1) = *(hex_digits + lo_nibble);
}

canonical_original_code:
static void hexdump_char(unsigned char c, char *str)
{
    static char *hex_digits = "0123456789abcdef";
    unsigned char hi_nibble = (c >> 4);
    unsigned char lo_nibble = c & 0x0F;
    *(str + 0) = *(hex_digits + hi_nibble);
    *(str + 1) = *(hex_digits + lo_nibble);
}

variable_types:
c
unsigned char

variable_types:
str
char *


decompiled_code:
__int64 __fastcall hexdump_word(int a1, _BYTE *a2)
{
hexdump_char(HIBYTE(a1), a2);
hexdump_char(BYTE2(a1), a2 + 2);
hexdump_char(BYTE1(a1), a2 + 4);
return hexdump_char(a1, a2 + 6);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, _BYTE *a2)
{
func0(HIBYTE(a1), a2);
func0(BYTE2(a1), a2 + 2);
func0(BYTE1(a1), a2 + 4);
return func0(a1, a2 + 6);
}

original_code:
static void
hexdump_word(uint32 word, char *str)
{
    hexdump_char(( word >> 24), &str[0]);
    hexdump_char(((word >> 16) & 0xFF), &str[2]);
    hexdump_char(((word >> 8) & 0xFF), &str[4]);
    hexdump_char(( word & 0xFF), &str[6]);
}

canonical_original_code:
static void hexdump_word(unsigned int word, char *str)
{
    hexdump_char(( word >> 24), &str[0]);
    hexdump_char(((word >> 16) & 0xFF), &str[2]);
    hexdump_char(((word >> 8) & 0xFF), &str[4]);
    hexdump_char(( word & 0xFF), &str[6]);
}

variable_types:
word
unsigned int


decompiled_code:
__int64 __fastcall get_uint32(__int64 a1, int a2)
{
return _byteswap_ulong(*(_DWORD *)(a1 + a2));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
return _byteswap_ulong(*(_DWORD *)(a1 + a2));
}

original_code:
static uint32
get_uint32(uint8 *buf, int idx)
{
    uint32 n = 0;
    n = ( buf[idx ] << 24 )
      | ( buf[idx + 1] << 16 )
      | ( buf[idx + 2] << 8 )
      | ( buf[idx + 3] );
    return n;
}

canonical_original_code:
static unsigned int get_uint32(unsigned char *buf, int idx)
{
    unsigned int n = 0;
    n = ( buf[idx ] << 24 )
      | ( buf[idx + 1] << 16 )
      | ( buf[idx + 2] << 8 )
      | ( buf[idx + 3] );
    return n;
}

variable_types:
buf
unsigned char *

variable_types: idx int

variable_types:
n
unsigned int

return_type: unsigned int


parity

decompiled_code:
__int64 __fastcall parity(int a1, unsigned int a2, int a3)
{
return a1 ^ a3 ^ a2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, unsigned int a2, int a3)
{
return a1 ^ a3 ^ a2;
}

original_code:
static uint32
parity(uint32 x, uint32 y, uint32 z)
{
    return (x ^ y ^ z);
}

canonical_original_code:
static unsigned int parity(unsigned int x, unsigned int y, unsigned int z)
{
    return (x ^ y ^ z);
}

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types:
z
unsigned int


maj

decompiled_code:
__int64 __fastcall maj(int a1, unsigned int a2, int a3)
{
return a3 & a2 | a1 & (a3 | a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, unsigned int a2, int a3)
{
return a3 & a2 | a1 & (a3 | a2);
}

original_code:
static uint32
maj(uint32 x, uint32 y, uint32 z)
{
    return (x & y) | (x & z) | (y & z);
}

canonical_original_code:
static unsigned int maj(unsigned int x, unsigned int y, unsigned int z)
{
    return (x & y) | (x & z) | (y & z);
}


init

original_code:
static void
init(struct sha_hash_s *hash)
{
    reset_block(hash->msg_block, 64);
    hash->msg_idx = 0;
    hash->hi_length = 0;
    hash->lo_length = 0;
    hash->h_sub[0] = 0x67452301;
    hash->h_sub[1] = 0xEFCDAB89;
    hash->h_sub[2] = 0x98BADCFE;
    hash->h_sub[3] = 0x10325476;
    hash->h_sub[4] = 0xC3D2E1F0;
}

variable_types: struct sha_hash_s { unsigned char msg_block[64]; unsigned char msg_idx; unsigned int hi_length; unsigned int lo_length; unsigned int h_sub[5]; } *


decompiled_code:
int __fastcall sha_hash_file_output(char *a1)
{
const char *v1; // rax
int result; // eax
const char *v3; // rax

if ( a1 )
{
v1 = (const char *)sha_hash_file(a1);
result = printf("%s %s\n", v1, a1);
}
else
{
v3 = (const char *)sha_hash_file(0LL);
result = printf("%s -\n", v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(char *a1)
{
const char *v1; // rax
int result; // eax
const char *v3; // rax

if ( a1 )
{
v1 = (const char *)func15(a1);
result = printf("%s %s\n", v1, a1);
}
else
{
v3 = (const char *)func15(0LL);
result = printf("%s -\n", v3);
}
return result;
}

original_code:
void
sha_hash_file_output(char *filename)
{
    if (filename == ((void *)0)) {
        printf("%s  -\n", sha_hash_file(filename));
    } else {
        printf("%s  %s\n", sha_hash_file(filename), filename);
    }
}

variable_types:
filename
char *


repo: jasper-lu/td-game

decompiled_code:
int __fastcall draw_variables(unsigned int *a1)
{
__syscall_slong_t v1; // rbp
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

clock_gettime(0, &v3);
v1 = v3.tv_nsec + 1000000000 * v3.tv_sec;
xt_par2("\x1B[%d;%dH", 40LL, 104LL);
printf("%d", **((unsigned int **)a1 + 2));
xt_par2("\x1B[%d;%dH", 41LL, 104LL);
printf(
"%d",
(unsigned int)((*(_QWORD *)(*((_QWORD *)a1 + 2) + 8LL) - (v1 - *(_QWORD *)(*((_QWORD *)a1 + 2) + 16LL))) / 1000000000)
+ 1);
xt_par2("\x1B[%d;%dH", 42LL, 104LL);
printf("%d", a1[1]);
xt_par2("\x1B[%d;%dH", 43LL, 104LL);
return printf("%d", *a1);
}

canonical_original_code:
static void draw_variables(struct game_t *game) {
    struct timespec temp;
    clock_gettime(0, &temp);
    long lm = temp.tv_sec * 1000000000 + temp.tv_nsec;
    xt_par2("\033[%d;%dH", (4 * 9 + 1*2 +2), (20*7 - 36));
    printf("%d", game->e_manager->level);
    xt_par2("\033[%d;%dH", (4 * 9 + 1*2 +3), (20*7 - 36));
    int countdown = (game->e_manager->wave_timer-(lm-game->e_manager->wave_load))/1000000000 +1;
    printf("%d", countdown);
    xt_par2("\033[%d;%dH", (4 * 9 + 1*2 +4), (20*7 - 36));
    printf("%d", game->lives);
    xt_par2("\033[%d;%dH", (4 * 9 + 1*2 +5), (20*7 - 36));
    printf("%d", game->money);
}

variable_types: struct game_t { int money; int lives; struct player_t { struct point_t { int x; int y; } point; } player; struct enemy_manager_t { int level; int spawn_numb; long wave_timer; long wave_load; int speed; long last_moved; int health; int money; struct enemy_t { struct point_t point; struct point_t dest; long move_timer; long last_moved; int health; int money; struct enemy_t *next; } *enemy_head; } *e_manager; struct tower_t { struct point_t point; int power; int radius; int b_speed; long cooldown; long cooldown_timer; int type; struct tower_t *next; } *tower_head; struct bullet_t { struct point_t point; int dmg; long move_timer; long last_moved; struct enemy_t *target; struct bullet_t *next; } *bullet_head; char **map; } *

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

variable_types: lm long

variable_types: countdown int

user_defined_types: struct game_t { int money; int lives; struct player_t player; struct enemy_manager_t *e_manager; struct tower_t *tower_head; struct bullet_t *bullet_head; char **map; }

user_defined_types: struct player_t { struct point_t point; }

user_defined_types: struct enemy_manager_t { int level; int spawn_numb; long wave_timer; long wave_load; int speed; long last_moved; int health; int money; struct enemy_t *enemy_head; }


original_code:
static void poll_all(game_t* game, char *c) {
    while((*c = getkey()) != -2){
        if ((*c == -10 || *c == 'w' )&& game->player.point.y > 0)
        {
            xt_par2("\033[%d;%dH",game->player.point.y--,game->player.point.x);
        }
        else if ( *c == 's' && game->player.point.y < 9 - 1)
        {
            xt_par2("\033[%d;%dH",game->player.point.y++,game->player.point.x);
        }
        else if ((*c == -12 || *c == 'd') && game->player.point.x < 20 - 1)
        {
            xt_par2("\033[%d;%dH",game->player.point.y,game->player.point.x++);
        }
        else if ((*c == -13 || *c == 'a') && game->player.point.x > 0)
        {
            xt_par2("\033[%d;%dH",game->player.point.y,game->player.point.x--);
        }
        else if (*c == '1')
        {
            spawn_tower(game, 1);
        }
    }
}

canonical_original_code:
static void poll_all(struct game_t *game, char *c) {
    while((*c = getkey()) != -2){
        if ((*c == -10 || *c == 'w' )&& game->player.point.y > 0)
        {
            xt_par2("\033[%d;%dH",game->player.point.y--,game->player.point.x);
        }
        else if ( *c == 's' && game->player.point.y < 9 - 1)
        {
            xt_par2("\033[%d;%dH",game->player.point.y++,game->player.point.x);
        }
        else if ((*c == -12 || *c == 'd') && game->player.point.x < 20 - 1)
        {
            xt_par2("\033[%d;%dH",game->player.point.y,game->player.point.x++);
        }
        else if ((*c == -13 || *c == 'a') && game->player.point.x > 0)
        {
            xt_par2("\033[%d;%dH",game->player.point.y,game->player.point.x--);
        }
        else if (*c == '1')
        {
            spawn_tower(game, 1);
        }
    }
}

variable_types:
c
char *

user_defined_types: struct tower_t { struct point_t point; int power; int radius; int b_speed; long cooldown; long cooldown_timer; int type; struct tower_t *next; }

user_defined_types: struct bullet_t { struct point_t point; int dmg; long move_timer; long last_moved; struct enemy_t *target; struct bullet_t *next; }

user_defined_types: struct enemy_t { struct point_t point; struct point_t dest; long move_timer; long last_moved; int health; int money; struct enemy_t *next; }


decompiled_code:
__int64 __fastcall exec_all(__int64 a1)
{
execute_bt();
execute_em(a1);
return execute_tw(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
execute_bt();
execute_em(a1);
return execute_tw(a1);
}

original_code:
static void exec_all(game_t* game) {
    execute_bt(game);
    execute_em(game);
    execute_tw(game);
}

canonical_original_code:
static void exec_all(struct game_t *game) {
    execute_bt(game);
    execute_em(game);
    execute_tw(game);
}


decompiled_code:
__int64 __fastcall draw_all(unsigned int *a1)
{
__int64 v1; // rbp
__int64 v2; // rax

xt_par0("\x1B[2J");
draw_ui();
draw_variables(a1);
draw_towers(a1);
v1 = get_sprite(0LL);
v2 = tile_convert(a1 + 2);
draw(v2, v1);
draw_bullets(a1);
draw_enemies(a1);
return xt_par2("\x1B[%d;%dH", 999LL, 999LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
__int64 v1; // rbp
__int64 v2; // rax

xt_par0("\x1B[2J");
draw_ui();
func1(a1);
draw_towers(a1);
v1 = get_sprite(0LL);
v2 = tile_convert(a1 + 2);
draw(v2, v1);
draw_bullets(a1);
draw_enemies(a1);
return xt_par2("\x1B[%d;%dH", 999LL, 999LL);
}

original_code:
static void draw_all(game_t* game){
    xt_par0("\033[2J");
    draw_ui();
    draw_variables(game);
    draw_towers(game);
    draw(tile_convert(&game->player.point), get_sprite(0));
    draw_bullets(game);
    draw_enemies(game);
        xt_par2("\033[%d;%dH",999,999);
}

canonical_original_code:
static void draw_all(struct game_t *game){
    xt_par0("\033[2J");
    draw_ui();
    draw_variables(game);
    draw_towers(game);
    draw(tile_convert(&game->player.point), get_sprite(0));
    draw_bullets(game);
    draw_enemies(game);
        xt_par2("\033[%d;%dH",999,999);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE *v3; // r13
__int64 v4; // rbp
__syscall_slong_t v5; // r12
__syscall_slong_t v6; // rbx
struct timespec v8; // [rsp+0h] [rbp-38h] BYREF

v3 = malloc(1uLL);
setbuf(stdout, 0LL);
v4 = init_game();
init_em(v4 + 16, 3LL);
init_map(v4, 20, 9);
spawn_player(v4);
clock_gettime(0, &v8);
v5 = v8.tv_nsec + 1000000000 * v8.tv_sec;
while ( 1 )
{
poll_all(v4, v3);
exec_all(v4);
clock_gettime(0, &v8);
v6 = v8.tv_nsec + 1000000000 * v8.tv_sec;
if ( v6 - v5 > 50000000 )
{
draw_all((unsigned int *)v4);
v5 = v6;
}
if ( *(int *)(v4 + 4) <= 0 )
break;
usleep(0x2710u);
}
getkey_terminate();
xt_par0("\x1B[2J");
if ( *(int *)(v4 + 4) <= 0 )
printf("YOU LOSE! HA!");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE *v3; // r13
__int64 v4; // rbp
__syscall_slong_t v5; // r12
__syscall_slong_t v6; // rbx
struct timespec v8; // [rsp+0h] [rbp-38h] BYREF

v3 = malloc(1uLL);
setbuf(stdout, 0LL);
v4 = init_game();
init_em(v4 + 16, 3LL);
func0(v4, 20, 9);
spawn_player(v4);
clock_gettime(0, &v8);
v5 = v8.tv_nsec + 1000000000 * v8.tv_sec;
while ( 1 )
{
func2(v4, v3);
func3(v4);
clock_gettime(0, &v8);
v6 = v8.tv_nsec + 1000000000 * v8.tv_sec;
if ( v6 - v5 > 50000000 )
{
func4((unsigned int *)v4);
v5 = v6;
}
if ( *(int *)(v4 + 4) <= 0 )
break;
usleep(0x2710u);
}
getkey_terminate();
xt_par0("\x1B[2J");
if ( *(int *)(v4 + 4) <= 0 )
printf("YOU LOSE! HA!");
return 0;
}

original_code:
int main() {
    char *c = malloc(sizeof(char));
    setbuf(stdout,((void *)0));
    game_t* game = init_game();
    init_em(&game->e_manager, 3);
    init_map(game, 20, 9);
    point_t point;
    spawn_player(game);
    struct timespec temp;
    clock_gettime(0, &temp);
    long last = temp.tv_sec * 1000000000 + temp.tv_nsec;
    long fps_timer = 1000000000 / 20;
    while(1) {
        poll_all(game, c);
        exec_all(game);
        clock_gettime(0, &temp);
        long lm = temp.tv_sec * 1000000000 + temp.tv_nsec;
        if(lm - last > fps_timer) {
            draw_all(game);
            last = lm;
        }
        if(game->lives <= 0) {
            break;
        }
        usleep(10000);
    }
    getkey_terminate();
        xt_par0("\033[2J");
    if(game->lives<=0) {
        printf("YOU LOSE! HA!");
    }
}

canonical_original_code:
int main() {
    char *c = malloc(sizeof(char));
    setbuf(stdout,((void *)0));
    struct game_t *game = init_game();
    init_em(&game->e_manager, 3);
    init_map(game, 20, 9);
    struct point_t point;
    spawn_player(game);
    struct timespec temp;
    clock_gettime(0, &temp);
    long last = temp.tv_sec * 1000000000 + temp.tv_nsec;
    long fps_timer = 1000000000 / 20;
    while(1) {
        poll_all(game, c);
        exec_all(game);
        clock_gettime(0, &temp);
        long lm = temp.tv_sec * 1000000000 + temp.tv_nsec;
        if(lm - last > fps_timer) {
            draw_all(game);
            last = lm;
        }
        if(game->lives <= 0) {
            break;
        }
        usleep(10000);
    }
    getkey_terminate();
        xt_par0("\033[2J");
    if(game->lives<=0) {
        printf("YOU LOSE! HA!");
    }
}

variable_types:
point
struct point_t { int x; int y; }

variable_types: last long

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


isBeginningOf

decompiled_code:
__int64 __fastcall isBeginningOf(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // dl
char v4; // cl

v2 = 0LL;
while ( 1 )
{
v3 = *(_BYTE *)(a2 + v2);
if ( !v3 )
break;
v4 = *(_BYTE *)(a1 + v2++);
if ( v4 != v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // dl
char v4; // cl

v2 = 0LL;
while ( 1 )
{
v3 = *(_BYTE *)(a2 + v2);
if ( !v3 )
break;
v4 = *(_BYTE *)(a1 + v2++);
if ( v4 != v3 )
return 0LL;
}
return 1LL;
}

original_code:
static int isBeginningOf(char *s, char *scode) {
 while (*scode) {
  if (*s++ != *scode++)
   return 0;
 }
 return 1;
}

variable_types:
s
char *

variable_types:
scode
char *


decompiled_code:
__int64 get_circ()
{
unsigned int v0; // esi

if ( !dword_358 )
return (unsigned int)-2;
v0 = circ[dword_354];
dword_354 = (dword_354 + 1) % 20;
--dword_358;
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // esi

if ( !dword_358 )
return (unsigned int)-2;
v0 = circ[dword_354];
dword_354 = (dword_354 + 1) % 20;
--dword_358;
return v0;
}

original_code:
static int get_circ(void) {
 int out_code;
 if (circ.in_buf == 0)
  return -2;
 out_code = circ.buf[circ.next_out++];
 circ.next_out %= 20;
 --circ.in_buf;
 return out_code;
}

canonical_original_code:
static int get_circ() {
 int out_code;
 if (circ.in_buf == 0)
  return -2;
 out_code = circ.buf[circ.next_out++];
 circ.next_out %= 20;
 --circ.in_buf;
 return out_code;
}


decompiled_code:
int getkey_terminate()
{
tcsetattr(0, 0, &oldt);
return fcntl(0, 4, (unsigned int)oldf);
}

canonical_decompiled_code:
int func4()
{
tcsetattr(0, 0, &oldt);
return fcntl(0, 4, (unsigned int)oldf);
}

original_code:
void getkey_terminate(void) {
 tcsetattr(0, 0, &oldt);
 fcntl(0, 4, oldf);
}

canonical_original_code:
void getkey_terminate() {
 tcsetattr(0, 0, &oldt);
 fcntl(0, 4, oldf);
}


decompiled_code:
int __fastcall xt_par0(const char *a1)
{
return printf("%s", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("%s", a1);
}

original_code:
void xt_par0(char *control_sequence) {
 printf("%s",control_sequence);
}


decompiled_code:
int __fastcall xt_par1(const char *a1)
{
return printf(a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf(a1);
}

original_code:
void xt_par1(char *control_sequence, int parameter1) {
 printf(control_sequence, parameter1);
}


decompiled_code:
int __fastcall xt_par2(const char *a1)
{
return printf(a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return printf(a1);
}

original_code:
void xt_par2(char *control_sequence, int parameter1, int parameter2) {
 printf(control_sequence, parameter1, parameter2);
}


user_defined_types: struct sprite_t { char *graphic[4]; int height; int width; char *color; }


decompiled_code:
unsigned __int64 __fastcall tile_convert(_DWORD *a1)
{
return ((unsigned __int64)(unsigned int)(4 * a1[1] + 2) << 32) | (unsigned int)(7 * *a1 + 2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(_DWORD *a1)
{
return ((unsigned __int64)(unsigned int)(4 * a1[1] + 2) << 32) | (unsigned int)(7 * *a1 + 2);
}

original_code:
point_t tile_convert(point_t* point) {
    return (point_t){point->x * 7 + 1 + 1, point->y * 4 + 1 + 1};
}

canonical_original_code:
struct point_t tile_convert(struct point_t *point) {
    return (struct point_t){point->x * 7 + 1 + 1, point->y * 4 + 1 + 1};
}

variable_types:
point
struct point_t *

return_type: struct point_t { int x; int y; }


draw

original_code:
void draw(point_t point, sprite_t* sprite) {
    int r, c;
    for(r = 0; r!= sprite->height; r++){
        xt_par2("\033[%d;%dH", (point.y + r), (point.x));
        for(c = 0; c!= sprite->width; ++c){
            putchar(sprite->graphic[r][c]);
        }
    }
    xt_par0("\033[0m");
}

canonical_original_code:
void draw(struct point_t point, struct sprite_t *sprite) {
    int r; int c;
    for(r = 0; r!= sprite->height; r++){
        xt_par2("\033[%d;%dH", (point.y + r), (point.x));
        for(c = 0; c!= sprite->width; ++c){
            putchar(sprite->graphic[r][c]);
        }
    }
    xt_par0("\033[0m");
}

variable_types: struct sprite_t { char *graphic[4]; int height; int width; char *color; } *

variable_types: r int

variable_types: c int


decompiled_code:
__int64 draw_ui()
{
unsigned int i; // ebx
unsigned int j; // ebx
const char **v2; // rbx
__int64 *v3; // rax

for ( i = 2; i != 44; ++i )
{
xt_par2("\x1B[%d;%dH", i, 1LL);
putchar(124);
xt_par2("\x1B[%d;%dH", i, 142LL);
putchar(124);
}
for ( j = 2; j != 142; ++j )
{
xt_par2("\x1B[%d;%dH", 1LL, j);
putchar(95);
}
v2 = (const char **)&UI;
do
{
xt_par2("\x1B[%d;%dH", *((unsigned int *)v2 + 1), (unsigned int)(*(_DWORD *)v2 + 2));
printf("%s", v2[2]);
v2 += 3;
}
while ( v2 != (const char **)&unk_8A0 );
v3 = get_sprite(1);
return draw(0x2700000003LL, (__int64)v3);
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int i; // ebx
unsigned int j; // ebx
const char **v2; // rbx
__int64 *v3; // rax

for ( i = 2; i != 44; ++i )
{
xt_par2("\x1B[%d;%dH", i, 1LL);
putchar(124);
xt_par2("\x1B[%d;%dH", i, 142LL);
putchar(124);
}
for ( j = 2; j != 142; ++j )
{
xt_par2("\x1B[%d;%dH", 1LL, j);
putchar(95);
}
v2 = (const char **)&UI;
do
{
xt_par2("\x1B[%d;%dH", *((unsigned int *)v2 + 1), (unsigned int)(*(_DWORD *)v2 + 2));
printf("%s", v2[2]);
v2 += 3;
}
while ( v2 != (const char **)&unk_8A0 );
v3 = get_sprite(1);
return func2(0x2700000003LL, (__int64)v3);
}

variable_types: i int


decompiled_code:
_DWORD *init_Node()
{
_DWORD *result; // rax

result = malloc(0x18uLL);
*result = 0;
result[1] = 0;
result[2] = 0;
result[3] = 0;
*((_QWORD *)result + 2) = 0LL;
return result;
}

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

result = malloc(0x18uLL);
*result = 0;
result[1] = 0;
result[2] = 0;
result[3] = 0;
*((_QWORD *)result + 2) = 0LL;
return result;
}

original_code:
Node* init_Node()
{
    Node* node;
    node = malloc(sizeof(Node));
    node->p.x=0;node->p.y=0;node->f=0;node->h=0;node->parent = ((void *)0);
    return node;
}

canonical_original_code:
struct Node *init_Node()
{
    struct Node *node;
    node = malloc(sizeof(Node));
    node->p.x=0;node->p.y=0;node->f=0;node->h=0;node->parent = ((void *)0);
    return node;
}

variable_types: struct Node { struct Point { int x; } p; int f; struct Node *parent; } *

user_defined_types: struct Node { struct Point p; int f; struct Node *parent; }


decompiled_code:
__int64 __fastcall init_Point(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

original_code:
Point init_Point(int x, int y)
{
    Point ret;
    ret.x = x; ret.y = y;
    return ret;
}

canonical_original_code:
struct Point init_Point(int x, int y)
{
    struct Point ret;
    ret.x = x; ret.y = y;
    return ret;
}

variable_types: x int

variable_types: y int

variable_types:
ret
struct Point { int x; }

return_type: struct Point { int x; }


compare

original_code:
int compare(Node* lhs, Node * rhs)
{
    return (lhs->f + lhs->h) - (rhs->f + rhs->h);
}

canonical_original_code:
int compare(struct Node *lhs, struct Node *rhs)
{
    return (lhs->f + lhs->h) - (rhs->f + rhs->h);
}

variable_types:
rhs
struct Node *


swap

decompiled_code:
void swap()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void swap(Node **a, Node **b)
{
    Node **temp = a;
    a = b;
    b = temp;
}

canonical_original_code:
void swap(struct Node **a, struct Node **b)
{
    struct Node **temp = a;
    a = b;
    b = temp;
}

variable_types: struct Node { struct Point { int x; } p; int f; struct Node *parent; } **

variable_types:
b
struct Node **


pop

original_code:
Node* pop(Node_heap * heap)
{
        Node* minElement;
 Node* lastElement;
 int now, child;
        minElement = heap->heap[1];
        lastElement = heap->heap[heap->size];
 heap->size--;
        for(now = 1; now*2 <= heap->size ;now = child)
        {
                child = now*2;
                if(child != heap->size && compare(heap->heap[child+1],heap->heap[child]) < 0)
                {
                        child++;
                }
                if(compare(lastElement,heap->heap[child]) > 0)
                {
                        heap->heap[now] = heap->heap[child];
                }
                else
                {
                        break;
                }
        }
        heap->heap[now] = lastElement;
        return minElement;
}

canonical_original_code:
struct Node *pop(struct Node_heap *heap)
{
        struct Node *minElement;
 struct Node *lastElement;
 int now; int child;
        minElement = heap->heap[1];
        lastElement = heap->heap[heap->size];
 heap->size--;
        for(now = 1; now*2 <= heap->size ;now = child)
        {
                child = now*2;
                if(child != heap->size && compare(heap->heap[child+1],heap->heap[child]) < 0)
                {
                        child++;
                }
                if(compare(lastElement,heap->heap[child]) > 0)
                {
                        heap->heap[now] = heap->heap[child];
                }
                else
                {
                        break;
                }
        }
        heap->heap[now] = lastElement;
        return minElement;
}

variable_types: struct Node_heap { struct Node **heap; int size; } *

variable_types: now int

variable_types: child int

return_type: struct Node { struct Point { int x; } p; int f; struct Node *parent; } *


getMin

decompiled_code:
__int64 __fastcall getMin(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)a1 + 8LL);
}

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

original_code:
Node* getMin(Node_heap *heap)
{
    return heap->heap[1];
}

canonical_original_code:
struct Node *getMin(struct Node_heap *heap)
{
    return heap->heap[1];
}

user_defined_types: struct Node_heap { struct Node **heap; int size; }


decompiled_code:
void __fastcall close_heap(void *ptr)
{
__int64 v1; // rax
__int64 v2; // rbx

if ( *((int *)ptr + 2) > 0 )
{
v1 = 0LL;
do
{
v2 = v1 + 1;
free(*(void **)(*(_QWORD *)ptr + 8 * (v1 + 1)));
v1 = v2;
}
while ( *((_DWORD *)ptr + 2) >= (int)v2 + 1 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
int close_heap(Node_heap *heap) {
    int i;
    for(i = 1; i <= heap->size; ++i)
 free(heap->heap[i]);
    free(heap->heap);
    free(heap);
}

canonical_original_code:
int close_heap(struct Node_heap *heap) {
    int i;
    for(i = 1; i <= heap->size; ++i)
 free(heap->heap[i]);
    free(heap->heap);
    free(heap);
}

variable_types: struct Node_heap { struct Node { struct Point { int x; } p; int f; struct Node *parent; } **heap; int size; } *


decompiled_code:
__int64 __fastcall init_mob(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

original_code:
Mob init_mob(int x, int y)
{
    Mob r;
    r.x = x;
    r.y = y;
    r.health = 100;
    r._n = 0;
    return r;
}

canonical_original_code:
struct Mob init_mob(int x, int y)
{
    struct Mob r;
    r.x = x;
    r.y = y;
    r.health = 100;
    r._n = 0;
    return r;
}

variable_types:
r
struct Mob { int x; }

return_type: struct Mob { int x; }


decompiled_code:
void __fastcall move_mob(unsigned int *a1, int a2, _QWORD *a3, __int64 a4)
{
unsigned int *v4; // rbx
__int64 v7; // rax

if ( a2 > 0 )
{
v4 = a1;
do
{
if ( (int)v4[3] > 0 )
{
v7 = init_Point(*v4, v4[1]);
*(_QWORD *)v4 = astar(v7, *a3, a4);
}
v4 += 4;
}
while ( v4 != &a1[4 * a2] );
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int *a1, int a2, _QWORD *a3, __int64 a4)
{
unsigned int *v4; // rbx
__int64 v7; // rax

if ( a2 > 0 )
{
v4 = a1;
do
{
if ( (int)v4[3] > 0 )
{
v7 = init_Point(*v4, v4[1]);
*(_QWORD *)v4 = astar(v7, *a3, a4);
}
v4 += 4;
}
while ( v4 != &a1[4 * a2] );
}
}

original_code:
void move_mob(Mob *mob, int mob_size, struct Point* end, char **map)
{
    int i;
    for(i = 0; i < mob_size; ++i)
    {
 if(mob-> health > 0)
 {
     Point b = astar(init_Point(mob->x,mob->y),*end,map);
     mob->x = b.x;
     mob->y = b.y;
 }
 ++mob;
    }
}

canonical_original_code:
void move_mob(struct Mob *mob, int mob_size, struct Point *end, char **map)
{
    int i;
    for(i = 0; i < mob_size; ++i)
    {
 if(mob-> health > 0)
 {
     struct Point b = astar(init_Point(mob->x,mob->y),*end,map);
     mob->x = b.x;
     mob->y = b.y;
 }
 ++mob;
    }
}

variable_types:
mob
struct Mob { int x; } *

variable_types:
end
struct Point { int x; } *

variable_types:
map
char **

variable_types:
b
struct Point { int x; }

user_defined_types:
struct Point { int x; }
struct Mob { int x; }


decompiled_code:
unsigned __int64 __fastcall init_Tower(unsigned int a1, unsigned int a2)
{
return __PAIR64__(a2, a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
return __PAIR64__(a2, a1);
}

original_code:
Tower init_Tower(int x, int y)
{
    Tower A;
    A.x = x; A.y = y; A.dmg = 10;
    return A;
}

canonical_original_code:
struct Tower init_Tower(int x, int y)
{
    struct Tower A;
    A.x = x; A.y = y; A.dmg = 10;
    return A;
}

variable_types:
A
struct Tower { int x; }

return_type: struct Tower { int x; }


original_code:
int tower_logic(Tower *a, Mob *b, int tower_size, int mob_size)
{
    int n, m;
    int ret = 0;
    for(m = 0; m < tower_size;++m)
    {
 for(n = 0; n != mob_size; ++n)
 {
     if(b->health > 0 && abs(a->x - b-> x) <= 2 && abs(a->y - b->y) <=2)
     {
  b->health = b->health - a->dmg;
  if (b->health == 0)
      ret++;
  break;
     }
     ++b;
 }
 ++a;
    }
    return ret;
}

canonical_original_code:
int tower_logic(struct Tower *a, struct Mob *b, int tower_size, int mob_size)
{
    int n; int m;
    int ret = 0;
    for(m = 0; m < tower_size;++m)
    {
 for(n = 0; n != mob_size; ++n)
 {
     if(b->health > 0 && abs(a->x - b-> x) <= 2 && abs(a->y - b->y) <=2)
     {
  b->health = b->health - a->dmg;
  if (b->health == 0)
      ret++;
  break;
     }
     ++b;
 }
 ++a;
    }
    return ret;
}

variable_types:
a
struct Tower { int x; } *

variable_types:
b
struct Mob { int x; } *

variable_types: n int

variable_types: m int

variable_types: ret int

user_defined_types:
struct Tower { int x; }
struct Mob { int x; }


loser

decompiled_code:
_BOOL8 __fastcall loser(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 )
result = a1[1] == a2[1];
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 )
result = a1[1] == a2[1];
return result;
}

original_code:
int loser(Mob* mob, struct Point* end)
{
    if(mob[0].x == end->x && mob[0].y == end->y)
 return 1;
    else
 return 0;
}

canonical_original_code:
int loser(struct Mob *mob, struct Point *end)
{
    if(mob[0].x == end->x && mob[0].y == end->y)
 return 1;
    else
 return 0;
}

user_defined_types:
struct Mob { int x; }
struct Point { int x; }


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

if ( *a2 <= 0 )
{
LABEL_5:
*a2 = 0;
result = 1LL;
}
else
{
v2 = a1 + 16LL * (unsigned int)*a2;
while ( *(int *)(a1 + 12) <= 0 )
{
a1 += 16LL;
if ( a1 == v2 )
goto LABEL_5;
}
result = 0LL;
}
return result;
}

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

if ( *a2 <= 0 )
{
LABEL_5:
*a2 = 0;
result = 1LL;
}
else
{
v2 = a1 + 16LL * (unsigned int)*a2;
while ( *(int *)(a1 + 12) <= 0 )
{
a1 += 16LL;
if ( a1 == v2 )
goto LABEL_5;
}
result = 0LL;
}
return result;
}

original_code:
int round_won(Mob* mob, int* mob_size)
{
    int i;
    for(i = 0; i < *mob_size; ++i)
    {
 if(mob->health > 0)
     return 0;
 ++mob;
    }
    *mob_size = 0;
    return 1;
}

canonical_original_code:
int round_won(struct Mob *mob, int *mob_size)
{
    int i;
    for(i = 0; i < *mob_size; ++i)
    {
 if(mob->health > 0)
     return 0;
 ++mob;
    }
    *mob_size = 0;
    return 1;
}

variable_types: i int


spawn

original_code:
int spawn(Mob* mob, int* mob_size, struct Point spawn_point, int count)
{
    mob[*mob_size] = init_mob(spawn_point.x,spawn_point.y);
    ++(*mob_size);
    return --count;
}

canonical_original_code:
int spawn(struct Mob *mob, int *mob_size, struct Point spawn_point, int count)
{
    mob[*mob_size] = init_mob(spawn_point.x,spawn_point.y);
    ++(*mob_size);
    return --count;
}

variable_types: count int


decompiled_code:
int __fastcall draw_mobs(_DWORD *a1, int a2)
{
_DWORD *v2; // rbx
int result; // eax

if ( a2 > 0 )
{
v2 = a1;
do
{
if ( (int)v2[3] > 0 )
{
xt_par2("\x1B[%d;%dH", (unsigned int)(v2[1] + 1), (unsigned int)(*v2 + 1));
result = putchar(77);
}
v2 += 4;
}
while ( v2 != &a1[4 * a2] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(_DWORD *a1, int a2)
{
_DWORD *v2; // rbx
int result; // eax

if ( a2 > 0 )
{
v2 = a1;
do
{
if ( (int)v2[3] > 0 )
{
xt_par2("\x1B[%d;%dH", (unsigned int)(v2[1] + 1), (unsigned int)(*v2 + 1));
result = putchar(77);
}
v2 += 4;
}
while ( v2 != &a1[4 * a2] );
}
return result;
}

original_code:
void draw_mobs(Mob *mobs, int n)
{
    int i;
    for(i = 0; i < n; ++i)
    {
 if(mobs->health > 0)
 {
     xt_par2("\033[%d;%dH",mobs->y+1,mobs->x+1);
     printf("M");
 }
 ++mobs;
    }
}

canonical_original_code:
void draw_mobs(struct Mob *mobs, int n)
{
    int i;
    for(i = 0; i < n; ++i)
    {
 if(mobs->health > 0)
 {
     xt_par2("\033[%d;%dH",mobs->y+1,mobs->x+1);
     printf("M");
 }
 ++mobs;
    }
}

variable_types:
mobs
struct Mob { int x; } *


decompiled_code:
int __fastcall draw_map(_QWORD *a1, int a2, int a3, _DWORD *a4, int a5, _DWORD *a6, int a7)
{
int v8; // er15
unsigned int v9; // er12
__int64 v10; // r15
__int64 v11; // rbx

v8 = a3;
printf("\x1B[32m");
if ( a2 )
{
v9 = 0;
v10 = (unsigned int)(v8 + 2);
do
{
v11 = 0LL;
if ( a3 != -2 )
{
do
{
if ( *(_BYTE *)(*a1 + v11) == 88 )
xt_par2("\x1B[44m", v9, (unsigned int)v11);
else
xt_par2("\x1B[49m", v9, (unsigned int)v11);
putchar(*(char *)(*a1 + v11));
xt_par2("\x1B[49m", v9, (unsigned int)v11++);
}
while ( v10 != v11 );
}
++v9;
++a1;
}
while ( v9 != a2 );
}
draw_towers(a4, a5);
return draw_mobs(a6, a7);
}

canonical_decompiled_code:
int __fastcall func2(_QWORD *a1, int a2, int a3, _DWORD *a4, int a5, _DWORD *a6, int a7)
{
int v8; // er15
unsigned int v9; // er12
__int64 v10; // r15
__int64 v11; // rbx

v8 = a3;
printf("\x1B[32m");
if ( a2 )
{
v9 = 0;
v10 = (unsigned int)(v8 + 2);
do
{
v11 = 0LL;
if ( a3 != -2 )
{
do
{
if ( *(_BYTE *)(*a1 + v11) == 88 )
xt_par2("\x1B[44m", v9, (unsigned int)v11);
else
xt_par2("\x1B[49m", v9, (unsigned int)v11);
putchar(*(char *)(*a1 + v11));
xt_par2("\x1B[49m", v9, (unsigned int)v11++);
}
while ( v10 != v11 );
}
++v9;
++a1;
}
while ( v9 != a2 );
}
func0(a4, a5);
return func1(a6, a7);
}

original_code:
void draw_map(char **map, const unsigned int row_size, const unsigned int col_size, Tower* arr, int arr_size, Mob* mobs, int mob_size)
{
    int r, c;
    printf("\033[32m");
    for(r = 0; r < row_size; ++r)
    {
 for(c = 0; c < col_size + 2; ++c)
 {
     char blah = map[r][c];
     if(blah == 'X')
     {
  xt_par2("\033[44m",r,c);
     }else if(blah == ' '){
  xt_par2("\033[49m",r,c);
     }else{
  xt_par2("\033[49m",r,c);
     }
     printf("%c", map[r][c]);
     xt_par2("\033[49m",r,c);
 }
    }
    draw_towers(arr,arr_size);
    draw_mobs(mobs,mob_size);
}

canonical_original_code:
void draw_map(char **map, unsigned int row_size, unsigned int col_size, struct Tower *arr, int arr_size, struct Mob *mobs, int mob_size)
{
    int r; int c;
    printf("\033[32m");
    for(r = 0; r < row_size; ++r)
    {
 for(c = 0; c < col_size + 2; ++c)
 {
     char blah = map[r][c];
     if(blah == 'X')
     {
  xt_par2("\033[44m",r,c);
     }else if(blah == ' '){
  xt_par2("\033[49m",r,c);
     }else{
  xt_par2("\033[49m",r,c);
     }
     printf("%c", map[r][c]);
     xt_par2("\033[49m",r,c);
 }
    }
    draw_towers(arr,arr_size);
    draw_mobs(mobs,mob_size);
}

variable_types:
arr
struct Tower { int x; } *

variable_types: r int

variable_types: c int

variable_types: blah char


decompiled_code:
int __fastcall init_map(_QWORD *a1)
{
FILE *v1; // r12
_QWORD *v2; // rbp
__int64 i; // rbx

v1 = fopen("map.txt", "r");
v2 = a1;
do
{
for ( i = 0LL; i != 21; ++i )
*(_BYTE *)(*v2 + i) = fgetc(v1);
++v2;
}
while ( v2 != a1 + 10 );
return fclose(v1);
}

canonical_decompiled_code:
int __fastcall func3(_QWORD *a1)
{
FILE *v1; // r12
_QWORD *v2; // rbp
__int64 i; // rbx

v1 = fopen("map.txt", "r");
v2 = a1;
do
{
for ( i = 0LL; i != 21; ++i )
*(_BYTE *)(*v2 + i) = fgetc(v1);
++v2;
}
while ( v2 != a1 + 10 );
return fclose(v1);
}

original_code:
static void init_map(game_t* game, int width, int height) {
    char ** map ;
    map = calloc(height+2, sizeof(char*));
    int i, j ;
    for(i = 0; i!= height + 2; ++i) {
        map[i] = calloc(width+2, sizeof(char));
    }
    for(i=0;i!= height + 2; ++i) {
        for(j=0;j!=width + 2; ++j) {
            if(i == 0 || j == 0 || i == height + 1 || j == width + 1 )
                map[i][j] = 'x';
            else
                map[i][j] = ' ';
        }
    }
    game->map = map;
}

canonical_original_code:
static void init_map(struct game_t *game, int width, int height) {
    char **map;
    map = calloc(height+2, sizeof(char *));
    int i; int j;
    for(i = 0; i!= height + 2; ++i) {
        map[i] = calloc(width+2, sizeof(char));
    }
    for(i=0;i!= height + 2; ++i) {
        for(j=0;j!=width + 2; ++j) {
            if(i == 0 || j == 0 || i == height + 1 || j == width + 1 )
                map[i][j] = 'x';
            else
                map[i][j] = ' ';
        }
    }
    game->map = map;
}

variable_types: struct game_t { int money; int lives; struct player_t { struct point_t { int x; int y; } point; } player; struct enemy_manager_t { int level; int spawn_numb; long wave_timer; long wave_load; int speed; long last_moved; int health; int money; struct enemy_t { struct point_t point; struct point_t dest; long move_timer; long last_moved; int health; int money; struct enemy_t *next; } *enemy_head; } *e_manager; struct tower_t { struct point_t point; int power; int radius; int b_speed; long cooldown; long cooldown_timer; int type; struct tower_t *next; } *tower_head; struct bullet_t { struct point_t point; int dmg; long move_timer; long last_moved; struct enemy_t *target; struct bullet_t *next; } *bullet_head; char **map; } *

variable_types: width int

variable_types: height int

variable_types: j int


decompiled_code:
int __fastcall draw_towers(_DWORD *a1, int a2)
{
_DWORD *v2; // rbx
int result; // eax

if ( a2 > 0 )
{
v2 = a1;
do
{
xt_par2("\x1B[%d;%dH", (unsigned int)(v2[1] + 1), (unsigned int)(*v2 + 1));
result = putchar(84);
v2 += 3;
}
while ( v2 != &a1[3 * (a2 - 1) + 3] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(_DWORD *a1, int a2)
{
_DWORD *v2; // rbx
int result; // eax

if ( a2 > 0 )
{
v2 = a1;
do
{
xt_par2("\x1B[%d;%dH", (unsigned int)(v2[1] + 1), (unsigned int)(*v2 + 1));
result = putchar(84);
v2 += 3;
}
while ( v2 != &a1[3 * (a2 - 1) + 3] );
}
return result;
}

original_code:
void draw_towers(Tower *arr, int n)
{
 int i;
 for (i = 0; i < n; ++i)
 {
     xt_par2("\033[%d;%dH",arr[i].y+1,arr[i].x+1);
     printf("T");
 }
}

canonical_original_code:
void draw_towers(struct Tower *arr, int n)
{
 int i;
 for (i = 0; i < n; ++i)
 {
     xt_par2("\033[%d;%dH",arr[i].y+1,arr[i].x+1);
     printf("T");
 }
}


main

repo: jasruf/IRI

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
InitServer(argc, argv, envp);
StartServer();
puts("Done.");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7(argc, argv, envp);
func8();
puts("Done.");
return 0;
}

original_code:
int main(int argc,char**argv)
{
 InitServer(argc,argv);
 StartServer();
 printf("Done.\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 InitServer(argc,argv);
 StartServer();
 printf("Done.\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


InitServer

decompiled_code:
__int64 InitServer()
{
puts("Initializing");
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
puts("Initializing");
return 0LL;
}

original_code:
int InitServer(const int argc,char**argv)
{
 printf("Initializing\n");
 return 0;
}

canonical_original_code:
int InitServer(int argc, char **argv)
{
 printf("Initializing\n");
 return 0;
}


StartServer

decompiled_code:
__int64 StartServer()
{
puts("Starting");
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
puts("Starting");
return 0LL;
}

original_code:
int StartServer(void)
{
 printf("Starting\n");
 return 0;
}

canonical_original_code:
int StartServer()
{
 printf("Starting\n");
 return 0;
}


repo: jats-ug/practice-ats

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

switch ( a1 )
{
case 1:
return printf("Paper");
case 2:
return printf("Scissors");
case 0:
result = printf("Rock");
break;
}
return result;
}

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

switch ( a1 )
{
case 1:
return printf("Paper");
case 2:
return printf("Scissors");
case 0:
result = printf("Rock");
break;
}
return result;
}

original_code:
void print_rps(rps_t x) {
 switch (x) {
 case R_RPS_T:
  printf("Rock"); break;
 case P_RPS_T:
  printf("Paper"); break;
 case S_RPS_T:
  printf("Scissors"); break;
 }
}

canonical_original_code:
void print_rps(enum rps_t x) {
 switch (x) {
 case R_RPS_T:
  printf("Rock"); break;
 case P_RPS_T:
  printf("Paper"); break;
 case S_RPS_T:
  printf("Scissors"); break;
 }
}

variable_types: enum rps_t { R_RPS_T=0, P_RPS_T=1, S_RPS_T=2 }


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

if ( a1 == 1 )
return 2LL;
result = 0LL;
if ( a1 != 2 )
{
result = 1LL;
if ( a1 )
abort();
}
return result;
}

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

if ( a1 == 1 )
return 2LL;
result = 0LL;
if ( a1 != 2 )
{
result = 1LL;
if ( a1 )
abort();
}
return result;
}

original_code:
rps_t rps_win_d(rps_t x) {
 switch (x) {
 case R_RPS_T:
  return P_RPS_T;
 case P_RPS_T:
  return S_RPS_T;
 case S_RPS_T:
  return R_RPS_T;
 default:
  abort();
 }
}

canonical_original_code:
enum rps_t rps_win_d(enum rps_t x) {
 switch (x) {
 case R_RPS_T:
  return P_RPS_T;
 case P_RPS_T:
  return S_RPS_T;
 case S_RPS_T:
  return R_RPS_T;
 default:
  abort();
 }
}

return_type: enum rps_t { R_RPS_T=0, P_RPS_T=1, S_RPS_T=2 }


decompiled_code:
__int64 __fastcall rps_even_d(int a1, int a2)
{
unsigned int v2; // ecx

v2 = a2 | (16 * a1);
if ( v2 > 0x21 || ((1LL << v2) & 0x200010004LL) == 0 )
abort();
return rps_win_d(a1);
}

original_code:
rps_t rps_even_d(rps_t x, rps_t y) {
 switch (((x)<<4 | (y))) {
 case ((P_RPS_T)<<4 | (R_RPS_T)):
 case ((S_RPS_T)<<4 | (P_RPS_T)):
 case ((R_RPS_T)<<4 | (S_RPS_T)):
  return rps_win_d(x);
 default:
  abort();
 }
}

canonical_original_code:
enum rps_t rps_even_d(enum rps_t x, enum rps_t y) {
 switch (((x)<<4 | (y))) {
 case ((P_RPS_T)<<4 | (R_RPS_T)):
 case ((S_RPS_T)<<4 | (P_RPS_T)):
 case ((R_RPS_T)<<4 | (S_RPS_T)):
  return rps_win_d(x);
 default:
  abort();
 }
}

user_defined_types: enum rps_t { R_RPS_T=0, P_RPS_T=1, S_RPS_T=2 }


main

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

v3 = rps_win_d(1);
print_rps(v3);
printf(" win ");
print_rps(1);
puts(".");
v4 = rps_even_d(v3, 1);
print_rps(v4);
printf(" is even between ");
print_rps(v3);
printf(" and ");
print_rps(1);
puts(".");
return 0;
}

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

v3 = func8(1);
func7(v3);
printf(" win ");
func7(1);
puts(".");
v4 = func9(v3, 1);
func7(v4);
printf(" is even between ");
func7(v3);
printf(" and ");
func7(1);
puts(".");
return 0;
}

original_code:
int main() {
 rps_t paper_d = P_RPS_T;
 rps_t win_d = rps_win_d (paper_d);
 print_rps(win_d); printf(" win "); print_rps(paper_d); printf(".\n");
 rps_t even_d = rps_even_d(win_d, paper_d);
 print_rps(even_d); printf(" is even between "); print_rps(win_d); printf(" and "); print_rps(paper_d); printf(".\n");
}

canonical_original_code:
int main() {
 enum rps_t paper_d = P_RPS_T;
 enum rps_t win_d = rps_win_d (paper_d);
 print_rps(win_d); printf(" win "); print_rps(paper_d); printf(".\n");
 enum rps_t even_d = rps_even_d(win_d, paper_d);
 print_rps(even_d); printf(" is even between "); print_rps(win_d); printf(" and "); print_rps(paper_d); printf(".\n");
}


tally

decompiled_code:
__int64 tally()
{
unsigned int v0; // ebx
__int64 i; // rbp
unsigned int v2; // er12
int v3; // eax

v0 = 0;
for ( i = 0LL; ; i = (unsigned int)(v3 + i) )
{
v2 = v0;
v3 = fgetc(stdin);
++v0;
if ( v3 < 0 )
break;
}
return (i << 32) | v2;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // ebx
__int64 i; // rbp
unsigned int v2; // er12
int v3; // eax

v0 = 0;
for ( i = 0LL; ; i = (unsigned int)(v3 + i) )
{
v2 = v0;
v3 = fgetc(stdin);
++v0;
if ( v3 < 0 )
break;
}
return (i << 32) | v2;
}

original_code:
res_t tally(void) {
 res_t res = {0, 0};
 int c;
 while ((c = fgetc(stdin)) >= 0) {
  res.count += 1;
  res.result += c;
 }
 return res;
}

canonical_original_code:
struct _res_struct tally() {
 struct _res_struct res = {0, 0};
 int c;
 while ((c = fgetc(stdin)) >= 0) {
  res.count += 1;
  res.result += c;
 }
 return res;
}

variable_types: struct _res_struct { int count; int result; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx

v3 = tally(argc, argv, envp);
printf("count=%d\n", (unsigned int)v3);
printf("result=%d\n", v3 >> 32);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx

v3 = func7(argc, argv, envp);
printf("count=%d\n", (unsigned int)v3);
printf("result=%d\n", v3 >> 32);
return 0;
}

original_code:
int main(void) {
 res_t res = tally();
 printf("count=%d\n", res.count);
 printf("result=%d\n", res.result);
}

canonical_original_code:
int main() {
 struct _res_struct res = tally();
 printf("count=%d\n", res.count);
 printf("result=%d\n", res.result);
}

user_defined_types: struct _res_struct { int count; int result; }


repo: javiplx/mini-snmpd

decompiled_code:
void handle_signal()
{
g_quit = 1;
}

canonical_decompiled_code:
void func0()
{
g_quit = 1;
}

original_code:
static void handle_signal(int signo)
{
 g_quit = 1;
}

variable_types: signo int


decompiled_code:
int print_version()
{
fwrite("Mini SNMP Daemon Version 1.1\n", 1uLL, 0x1DuLL, stderr);
fwrite("A minimal simple network management protocol daemon for embedded Linux\n", 1uLL, 0x47uLL, stderr);
fputc(10, stderr);
fwrite("Copyright (C) 2008 Robert Ernst <robert.ernst@aon.at>\n", 1uLL, 0x36uLL, stderr);
fputc(10, stderr);
fwrite("This program is free software; you can redistribute it and/or modify\n", 1uLL, 0x45uLL, stderr);
fwrite("it under the terms of the GNU General Public License as published by\n", 1uLL, 0x45uLL, stderr);
fwrite("the Free Software Foundation; either version 2 of the License, or\n", 1uLL, 0x42uLL, stderr);
fwrite("(at your option) any later version.\n", 1uLL, 0x24uLL, stderr);
fputc(10, stderr);
fwrite("This program is distributed in the hope that it will be useful,\n", 1uLL, 0x40uLL, stderr);
fwrite("but WITHOUT ANY WARRANTY; without even the implied warranty of\n", 1uLL, 0x3FuLL, stderr);
fwrite("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n", 1uLL, 0x3EuLL, stderr);
fwrite("GNU General Public License for more details.\n", 1uLL, 0x2DuLL, stderr);
fputc(10, stderr);
fwrite("You should have received a copy of the GNU General Public License\n", 1uLL, 0x42uLL, stderr);
fwrite("along with this program; if not, write to the Free Software\n", 1uLL, 0x3CuLL, stderr);
fwrite("Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n", 1uLL, 0x4AuLL, stderr);
return fputc(10, stderr);
}

canonical_decompiled_code:
int func1()
{
fwrite("Mini SNMP Daemon Version 1.1\n", 1uLL, 0x1DuLL, stderr);
fwrite("A minimal simple network management protocol daemon for embedded Linux\n", 1uLL, 0x47uLL, stderr);
fputc(10, stderr);
fwrite("Copyright (C) 2008 Robert Ernst <robert.ernst@aon.at>\n", 1uLL, 0x36uLL, stderr);
fputc(10, stderr);
fwrite("This program is free software; you can redistribute it and/or modify\n", 1uLL, 0x45uLL, stderr);
fwrite("it under the terms of the GNU General Public License as published by\n", 1uLL, 0x45uLL, stderr);
fwrite("the Free Software Foundation; either version 2 of the License, or\n", 1uLL, 0x42uLL, stderr);
fwrite("(at your option) any later version.\n", 1uLL, 0x24uLL, stderr);
fputc(10, stderr);
fwrite("This program is distributed in the hope that it will be useful,\n", 1uLL, 0x40uLL, stderr);
fwrite("but WITHOUT ANY WARRANTY; without even the implied warranty of\n", 1uLL, 0x3FuLL, stderr);
fwrite("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n", 1uLL, 0x3EuLL, stderr);
fwrite("GNU General Public License for more details.\n", 1uLL, 0x2DuLL, stderr);
fputc(10, stderr);
fwrite("You should have received a copy of the GNU General Public License\n", 1uLL, 0x42uLL, stderr);
fwrite("along with this program; if not, write to the Free Software\n", 1uLL, 0x3CuLL, stderr);
fwrite("Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n", 1uLL, 0x4AuLL, stderr);
return fputc(10, stderr);
}

original_code:
static void print_version(void)
{
 fprintf(stderr, "Mini SNMP Daemon Version " "1.1" "\n");
 fprintf(stderr, "A minimal simple network management protocol daemon for embedded Linux\n");
 fprintf(stderr, "\n");
 fprintf(stderr, "Copyright (C) 2008 Robert Ernst <robert.ernst@aon.at>\n");
 fprintf(stderr, "\n");
 fprintf(stderr, "This program is free software; you can redistribute it and/or modify\n");
 fprintf(stderr, "it under the terms of the GNU General Public License as published by\n");
 fprintf(stderr, "the Free Software Foundation; either version 2 of the License, or\n");
 fprintf(stderr, "(at your option) any later version.\n");
 fprintf(stderr, "\n");
 fprintf(stderr, "This program is distributed in the hope that it will be useful,\n");
 fprintf(stderr, "but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
 fprintf(stderr, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");
 fprintf(stderr, "GNU General Public License for more details.\n");
 fprintf(stderr, "\n");
 fprintf(stderr, "You should have received a copy of the GNU General Public License\n");
 fprintf(stderr, "along with this program; if not, write to the Free Software\n");
 fprintf(stderr, "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n");
 fprintf(stderr, "\n");
}

canonical_original_code:
static void print_version()
{
 fprintf(stderr, "Mini SNMP Daemon Version " "1.1" "\n");
 fprintf(stderr, "A minimal simple network management protocol daemon for embedded Linux\n");
 fprintf(stderr, "\n");
 fprintf(stderr, "Copyright (C) 2008 Robert Ernst <robert.ernst@aon.at>\n");
 fprintf(stderr, "\n");
 fprintf(stderr, "This program is free software; you can redistribute it and/or modify\n");
 fprintf(stderr, "it under the terms of the GNU General Public License as published by\n");
 fprintf(stderr, "the Free Software Foundation; either version 2 of the License, or\n");
 fprintf(stderr, "(at your option) any later version.\n");
 fprintf(stderr, "\n");
 fprintf(stderr, "This program is distributed in the hope that it will be useful,\n");
 fprintf(stderr, "but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
 fprintf(stderr, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");
 fprintf(stderr, "GNU General Public License for more details.\n");
 fprintf(stderr, "\n");
 fprintf(stderr, "You should have received a copy of the GNU General Public License\n");
 fprintf(stderr, "along with this program; if not, write to the Free Software\n");
 fprintf(stderr, "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n");
 fprintf(stderr, "\n");
}


decompiled_code:
int print_help()
{
fwrite("usage: mini_snmpd [options]\n", 1uLL, 0x1CuLL, stderr);
fputc(10, stderr);
fwrite("-p, --udp-port nnn set the UDP port to bind to (161)\n", 1uLL, 0x39uLL, stderr);
fwrite("-c, --community nnn set the community string (public)\n", 1uLL, 0x39uLL, stderr);
fwrite("-D, --description nnn set the system description (empty)\n", 1uLL, 0x3AuLL, stderr);
fwrite("-V, --vendor nnn set the system vendor (empty)\n", 1uLL, 0x35uLL, stderr);
fwrite("-L, --location nnn set the system location (empty)\n", 1uLL, 0x37uLL, stderr);
fwrite("-C, --contact nnn set the system contact (empty)\n", 1uLL, 0x36uLL, stderr);
fwrite("-d, --disks nnn set the disks to monitor (/)\n", 1uLL, 0x34uLL, stderr);
fwrite("-i, --interfaces nnn set the network interfaces to monitor (lo)\n", 1uLL, 0x42uLL, stderr);
fwrite("-t, --timeout nnn set the timeout for MIB updates (1 second)\n", 1uLL, 0x42uLL, stderr);
fwrite("-a, --auth require authentication (thus SNMP version 2c)\n", 1uLL, 0x45uLL, stderr);
fwrite("-v, --verbose verbose syslog messages \n", 1uLL, 0x30uLL, stderr);
fwrite("-l, --licensing print licensing info and exit\n", 1uLL, 0x35uLL, stderr);
fwrite("-h, --help print this help and exit\n", 1uLL, 0x30uLL, stderr);
return fputc(10, stderr);
}

canonical_decompiled_code:
int func2()
{
fwrite("usage: mini_snmpd [options]\n", 1uLL, 0x1CuLL, stderr);
fputc(10, stderr);
fwrite("-p, --udp-port nnn set the UDP port to bind to (161)\n", 1uLL, 0x39uLL, stderr);
fwrite("-c, --community nnn set the community string (public)\n", 1uLL, 0x39uLL, stderr);
fwrite("-D, --description nnn set the system description (empty)\n", 1uLL, 0x3AuLL, stderr);
fwrite("-V, --vendor nnn set the system vendor (empty)\n", 1uLL, 0x35uLL, stderr);
fwrite("-L, --location nnn set the system location (empty)\n", 1uLL, 0x37uLL, stderr);
fwrite("-C, --contact nnn set the system contact (empty)\n", 1uLL, 0x36uLL, stderr);
fwrite("-d, --disks nnn set the disks to monitor (/)\n", 1uLL, 0x34uLL, stderr);
fwrite("-i, --interfaces nnn set the network interfaces to monitor (lo)\n", 1uLL, 0x42uLL, stderr);
fwrite("-t, --timeout nnn set the timeout for MIB updates (1 second)\n", 1uLL, 0x42uLL, stderr);
fwrite("-a, --auth require authentication (thus SNMP version 2c)\n", 1uLL, 0x45uLL, stderr);
fwrite("-v, --verbose verbose syslog messages \n", 1uLL, 0x30uLL, stderr);
fwrite("-l, --licensing print licensing info and exit\n", 1uLL, 0x35uLL, stderr);
fwrite("-h, --help print this help and exit\n", 1uLL, 0x30uLL, stderr);
return fputc(10, stderr);
}

original_code:
static void print_help(void)
{
 fprintf(stderr, "usage: mini_snmpd [options]\n");
 fprintf(stderr, "\n");
 fprintf(stderr, "-p, --udp-port nnn     set the UDP port to bind to (161)\n");
 fprintf(stderr, "-c, --community nnn    set the community string (public)\n");
 fprintf(stderr, "-D, --description nnn  set the system description (empty)\n");
 fprintf(stderr, "-V, --vendor nnn       set the system vendor (empty)\n");
 fprintf(stderr, "-L, --location nnn     set the system location (empty)\n");
 fprintf(stderr, "-C, --contact nnn      set the system contact (empty)\n");
 fprintf(stderr, "-d, --disks nnn        set the disks to monitor (/)\n");
 fprintf(stderr, "-i, --interfaces nnn   set the network interfaces to monitor (lo)\n");
 fprintf(stderr, "-t, --timeout nnn      set the timeout for MIB updates (1 second)\n");
 fprintf(stderr, "-a, --auth             require authentication (thus SNMP version 2c)\n");
 fprintf(stderr, "-v, --verbose          verbose syslog messages \n");
 fprintf(stderr, "-l, --licensing        print licensing info and exit\n");
 fprintf(stderr, "-h, --help             print this help and exit\n");
 fprintf(stderr, "\n");
}

canonical_original_code:
static void print_help()
{
 fprintf(stderr, "usage: mini_snmpd [options]\n");
 fprintf(stderr, "\n");
 fprintf(stderr, "-p, --udp-port nnn     set the UDP port to bind to (161)\n");
 fprintf(stderr, "-c, --community nnn    set the community string (public)\n");
 fprintf(stderr, "-D, --description nnn  set the system description (empty)\n");
 fprintf(stderr, "-V, --vendor nnn       set the system vendor (empty)\n");
 fprintf(stderr, "-L, --location nnn     set the system location (empty)\n");
 fprintf(stderr, "-C, --contact nnn      set the system contact (empty)\n");
 fprintf(stderr, "-d, --disks nnn        set the disks to monitor (/)\n");
 fprintf(stderr, "-i, --interfaces nnn   set the network interfaces to monitor (lo)\n");
 fprintf(stderr, "-t, --timeout nnn      set the timeout for MIB updates (1 second)\n");
 fprintf(stderr, "-a, --auth             require authentication (thus SNMP version 2c)\n");
 fprintf(stderr, "-v, --verbose          verbose syslog messages \n");
 fprintf(stderr, "-l, --licensing        print licensing info and exit\n");
 fprintf(stderr, "-h, --help             print this help and exit\n");
 fprintf(stderr, "\n");
}


decompiled_code:
int handle_udp_client()
{
int v0; // eax
int v1; // ebx
size_t v2; // rdx
unsigned int v3; // ebx
__int64 v4; // r9
char v6[60]; // [rsp+0h] [rbp-68h] BYREF
socklen_t addr_len; // [rsp+3Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+40h] [rbp-28h] BYREF

addr_len = 28;
v0 = recvfrom(g_udp_sockfd, (void *)(unsigned int)((_DWORD)&g_udp_client + 30), 0x800uLL, 0, &addr, &addr_len);
if ( *((_QWORD *)&g_udp_client + 260) == -1LL )
return fprintf(stderr, "could not receive packet on UDP port %d: %m\n", g_udp_port);
v1 = v0;
g_udp_client = time(0LL);
*((_DWORD *)&g_udp_client + 2) = g_udp_sockfd;
*(__m128i *)((char *)&g_udp_client + 12) = _mm_loadu_si128((const __m128i *)&addr.sa_data[6]);
*((_WORD *)&g_udp_client + 14) = *(_WORD *)addr.sa_data;
*((_QWORD *)&g_udp_client + 260) = v1;
*((_DWORD *)&g_udp_client + 522) = 0;
dump_packet(&g_udp_client);
inet_ntop(10, &addr.sa_data[6], v6, 0x2Eu);
if ( (unsigned int)snmp(&g_udp_client) == -1 )
return fprintf(stderr, "could not handle packet from UDP client %s:%d: %m\n", v6, *(unsigned __int16 *)addr.sa_data);
v2 = *((_QWORD *)&g_udp_client + 260);
if ( !v2 )
return fprintf(
stderr,
"could not handle packet from UDP client %s:%d: ignored\n",
v6,
*(unsigned __int16 *)addr.sa_data);
*((_DWORD *)&g_udp_client + 522) = 1;
v3 = sendto(g_udp_sockfd, (const void *)(unsigned int)((_DWORD)&g_udp_client + 30), v2, 64, &addr, addr_len);
inet_ntop(10, &addr.sa_data[6], v6, 0x2Eu);
if ( v3 == -1 )
{
fprintf(stderr, "could not send packet to UDP client %s:%d: %m\n", v6, *(unsigned __int16 *)addr.sa_data);
}
else
{
v4 = *((_QWORD *)&g_udp_client + 260);
if ( v3 != v4 )
fprintf(
stderr,
"could not send packet to UDP client %s:%d: only %d of %d bytes written\n",
v6,
*(unsigned __int16 *)addr.sa_data,
v3,
v4);
}
return dump_packet(&g_udp_client);
}

canonical_decompiled_code:
int func4()
{
int v0; // eax
int v1; // ebx
size_t v2; // rdx
unsigned int v3; // ebx
__int64 v4; // r9
char v6[60]; // [rsp+0h] [rbp-68h] BYREF
socklen_t addr_len; // [rsp+3Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+40h] [rbp-28h] BYREF

addr_len = 28;
v0 = recvfrom(g_udp_sockfd, (void *)(unsigned int)((_DWORD)&g_udp_client + 30), 0x800uLL, 0, &addr, &addr_len);
if ( *((_QWORD *)&g_udp_client + 260) == -1LL )
return fprintf(stderr, "could not receive packet on UDP port %d: %m\n", g_udp_port);
v1 = v0;
g_udp_client = time(0LL);
*((_DWORD *)&g_udp_client + 2) = g_udp_sockfd;
*(__m128i *)((char *)&g_udp_client + 12) = _mm_loadu_si128((const __m128i *)&addr.sa_data[6]);
*((_WORD *)&g_udp_client + 14) = *(_WORD *)addr.sa_data;
*((_QWORD *)&g_udp_client + 260) = v1;
*((_DWORD *)&g_udp_client + 522) = 0;
dump_packet(&g_udp_client);
inet_ntop(10, &addr.sa_data[6], v6, 0x2Eu);
if ( (unsigned int)snmp(&g_udp_client) == -1 )
return fprintf(stderr, "could not handle packet from UDP client %s:%d: %m\n", v6, *(unsigned __int16 *)addr.sa_data);
v2 = *((_QWORD *)&g_udp_client + 260);
if ( !v2 )
return fprintf(
stderr,
"could not handle packet from UDP client %s:%d: ignored\n",
v6,
*(unsigned __int16 *)addr.sa_data);
*((_DWORD *)&g_udp_client + 522) = 1;
v3 = sendto(g_udp_sockfd, (const void *)(unsigned int)((_DWORD)&g_udp_client + 30), v2, 64, &addr, addr_len);
inet_ntop(10, &addr.sa_data[6], v6, 0x2Eu);
if ( v3 == -1 )
{
fprintf(stderr, "could not send packet to UDP client %s:%d: %m\n", v6, *(unsigned __int16 *)addr.sa_data);
}
else
{
v4 = *((_QWORD *)&g_udp_client + 260);
if ( v3 != v4 )
fprintf(
stderr,
"could not send packet to UDP client %s:%d: only %d of %d bytes written\n",
v6,
*(unsigned __int16 *)addr.sa_data,
v3,
v4);
}
return dump_packet(&g_udp_client);
}

original_code:
static void handle_udp_client(void)
{
 struct sockaddr_in6 sockaddr;
 socklen_t socklen;
 int rv;
 char straddr[46];
 socklen = sizeof (sockaddr);
 rv = recvfrom(g_udp_sockfd, g_udp_client.packet, sizeof (g_udp_client.packet),
  0, (struct sockaddr *)&sockaddr, &socklen);
 if (g_udp_client.size == -1) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not receive packet on UDP port %d: %m\n", g_udp_port); } } while (0);
  return;
 }
 g_udp_client.timestamp = time(((void *)0));
 g_udp_client.sockfd = g_udp_sockfd;
 g_udp_client.addr = sockaddr.sin6_addr;
 g_udp_client.port = sockaddr.sin6_port;
 g_udp_client.size = rv;
 g_udp_client.outgoing = 0;
 dump_packet(&g_udp_client);
 inet_ntop(10, &sockaddr.sin6_addr, straddr, sizeof(straddr));
 if (snmp(&g_udp_client) == -1) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not handle packet from UDP client %s:%d: %m\n", straddr, sockaddr.sin6_port); } } while (0);
  return;
 } else if (g_udp_client.size == 0) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not handle packet from UDP client %s:%d: ignored\n", straddr, sockaddr.sin6_port); } } while (0);
  return;
 }
 g_udp_client.outgoing = 1;
 rv = sendto(g_udp_sockfd, g_udp_client.packet, g_udp_client.size,
  MSG_DONTWAIT, (struct sockaddr *)&sockaddr, socklen);
 inet_ntop(10, &sockaddr.sin6_addr, straddr, sizeof(straddr));
 if (rv == -1) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not send packet to UDP client %s:%d: %m\n", straddr, sockaddr.sin6_port); } } while (0);
 } else if (rv != g_udp_client.size) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not send packet to UDP client %s:%d: " "only %d of %d bytes written\n", straddr, sockaddr.sin6_port, rv, (int) g_udp_client.size); } } while (0);
 }
 dump_packet(&g_udp_client);
}

canonical_original_code:
static void handle_udp_client()
{
 struct sockaddr_in6 sockaddr;
 unsigned int socklen;
 int rv;
 char straddr[46];
 socklen = sizeof (sockaddr);
 rv = recvfrom(g_udp_sockfd, g_udp_client.packet, sizeof (g_udp_client.packet),
  0, (struct sockaddr *)&sockaddr, &socklen);
 if (g_udp_client.size == -1) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not receive packet on UDP port %d: %m\n", g_udp_port); } } while (0);
  return;
 }
 g_udp_client.timestamp = time(((void *)0));
 g_udp_client.sockfd = g_udp_sockfd;
 g_udp_client.addr = sockaddr.sin6_addr;
 g_udp_client.port = sockaddr.sin6_port;
 g_udp_client.size = rv;
 g_udp_client.outgoing = 0;
 dump_packet(&g_udp_client);
 inet_ntop(10, &sockaddr.sin6_addr, straddr, sizeof(straddr));
 if (snmp(&g_udp_client) == -1) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not handle packet from UDP client %s:%d: %m\n", straddr, sockaddr.sin6_port); } } while (0);
  return;
 } else if (g_udp_client.size == 0) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not handle packet from UDP client %s:%d: ignored\n", straddr, sockaddr.sin6_port); } } while (0);
  return;
 }
 g_udp_client.outgoing = 1;
 rv = sendto(g_udp_sockfd, g_udp_client.packet, g_udp_client.size,
  MSG_DONTWAIT, (struct sockaddr *)&sockaddr, socklen);
 inet_ntop(10, &sockaddr.sin6_addr, straddr, sizeof(straddr));
 if (rv == -1) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not send packet to UDP client %s:%d: %m\n", straddr, sockaddr.sin6_port); } } while (0);
 } else if (rv != g_udp_client.size) {
  do { if (g_verbose || (4 != 7)) { fprintf(stderr, "could not send packet to UDP client %s:%d: " "only %d of %d bytes written\n", straddr, sockaddr.sin6_port, rv, (int) g_udp_client.size); } } while (0);
 }
 dump_packet(&g_udp_client);
}

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

variable_types:
socklen
unsigned int

variable_types: rv int

variable_types:
straddr
char [46]

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

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


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int v6; // edi
int v7; // eax
int v8; // ebp
fd_set v9; // [rsp+0h] [rbp-E8h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-68h] BYREF
__m128i v11; // [rsp+90h] [rbp-58h] BYREF
struct timeval tv; // [rsp+A0h] [rbp-48h] BYREF
char addr[24]; // [rsp+B0h] [rbp-38h] BYREF
int longind[7]; // [rsp+CCh] [rbp-1Ch] BYREF

longind[0] = 1;
signal(15, (__sighandler_t)handle_signal);
signal(1, (__sighandler_t)handle_signal);
siginterrupt(15, 0);
siginterrupt(1, 0);
while ( 1 )
{
v3 = getopt_long(argc, (char *const *)argv, "p:c:D:V:L:C:d:i:t:T:avlh", &long_options_0, longind);
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'C':
g_contact = strdup(optarg);
break;
case 'D':
g_description = strdup(optarg);
break;
case 'L':
g_location = strdup(optarg);
break;
case 'V':
g_vendor = strdup(optarg);
break;
case 'a':
g_auth = 1;
break;
case 'c':
g_community = strdup(optarg);
break;
case 'd':
g_disk_list_length = split(optarg, ",:;", &g_disk_list, 4LL);
break;
case 'i':
g_interface_list_length = split(optarg, ",:;", &g_interface_list, 4LL);
break;
case 'l':
print_version();
exit(1);
case 'p':
g_udp_port = atoi(optarg);
break;
case 't':
g_timeout = 100 * atoi(optarg);
break;
case 'v':
g_verbose = 1;
break;
default:
print_help();
exit(1);
}
}
fprintf(stderr, "started, listening on port %d/udp\n", g_udp_port);
if ( gettimeofday(&tv, 0LL) == -1 )
{
tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
timeout.tv_sec = 0LL;
}
else
{
timeout.tv_sec = g_timeout / 100;
timeout.tv_usec = 10000 * (g_timeout % 100);
}
if ( (unsigned int)mib_build() == -1 )
exit(2);
if ( (unsigned int)mib_update(1LL) == -1 )
exit(2);
dump_mib(&g_mib, g_mib_length);
v4 = socket(10, 2, 0);
g_udp_sockfd = v4;
if ( v4 == -1 )
{
fprintf(stderr, "could not create UDP socket: %m\n");
exit(2);
}
*(_WORD *)addr = 10;
*(_WORD *)&addr[2] = _bswap_16(g_udp_port);
*(__m128i *)&addr[8] = _mm_loadu_si128((const __m128i *)&in6addr_any);
if ( bind(v4, (const struct sockaddr *)addr, 0x1Cu) == -1 )
{
fprintf(stderr, "could not bind UDP socket to port %d: %m\n", g_udp_port);
exit(2);
}
while ( !g_quit )
{
memset(&v9, 0, sizeof(v9));
v6 = g_udp_sockfd;
v9.fds_bits[g_udp_sockfd / 64] |= 1LL << (g_udp_sockfd % 64);
if ( select(v6 + 1, &v9, 0LL, 0LL, &timeout) == -1 )
{
if ( !g_quit )
{
fprintf(stderr, "could not select from sockets: %m\n");
exit(2);
}
break;
}
v7 = ticks_since(&tv, &v11);
v8 = v7;
if ( v7 < 0 || g_timeout <= v7 )
{
if ( g_verbose )
fwrite("updating the MIB (full)\n", 1uLL, 0x18uLL, stderr);
if ( (unsigned int)mib_update(1LL) == -1 )
exit(2);
tv = (struct timeval)_mm_loadu_si128(&v11);
timeout.tv_sec = g_timeout / 100;
timeout.tv_usec = 10000 * (g_timeout % 100);
}
else
{
if ( g_verbose )
fwrite("updating the MIB (partial)\n", 1uLL, 0x1BuLL, stderr);
if ( (unsigned int)mib_update(0LL) == -1 )
exit(2);
timeout.tv_sec = (g_timeout - v8) / 100;
timeout.tv_usec = 10000 * ((g_timeout - v8) % 100);
}
dump_mib(&g_mib, g_mib_length);
if ( (v9.fds_bits[g_udp_sockfd / 64] & (1LL << (g_udp_sockfd % 64))) != 0 )
handle_udp_client();
}
fwrite("stopped\n", 1uLL, 8uLL, stderr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int v6; // edi
int v7; // eax
int v8; // ebp
fd_set v9; // [rsp+0h] [rbp-E8h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-68h] BYREF
__m128i v11; // [rsp+90h] [rbp-58h] BYREF
struct timeval tv; // [rsp+A0h] [rbp-48h] BYREF
char addr[24]; // [rsp+B0h] [rbp-38h] BYREF
int longind[7]; // [rsp+CCh] [rbp-1Ch] BYREF

longind[0] = 1;
signal(15, (__sighandler_t)handle_signal);
signal(1, (__sighandler_t)handle_signal);
siginterrupt(15, 0);
siginterrupt(1, 0);
while ( 1 )
{
v3 = getopt_long(argc, (char *const *)argv, "p:c:D:V:L:C:d:i:t:T:avlh", &long_options_0, longind);
if ( v3 == -1 )
break;
switch ( v3 )
{
case 'C':
g_contact = strdup(optarg);
break;
case 'D':
g_description = strdup(optarg);
break;
case 'L':
g_location = strdup(optarg);
break;
case 'V':
g_vendor = strdup(optarg);
break;
case 'a':
g_auth = 1;
break;
case 'c':
g_community = strdup(optarg);
break;
case 'd':
g_disk_list_length = split(optarg, ",:;", &g_disk_list, 4LL);
break;
case 'i':
g_interface_list_length = split(optarg, ",:;", &g_interface_list, 4LL);
break;
case 'l':
func1();
exit(1);
case 'p':
g_udp_port = atoi(optarg);
break;
case 't':
g_timeout = 100 * atoi(optarg);
break;
case 'v':
g_verbose = 1;
break;
default:
func2();
exit(1);
}
}
fprintf(stderr, "started, listening on port %d/udp\n", g_udp_port);
if ( gettimeofday(&tv, 0LL) == -1 )
{
tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
timeout.tv_sec = 0LL;
}
else
{
timeout.tv_sec = g_timeout / 100;
timeout.tv_usec = 10000 * (g_timeout % 100);
}
if ( (unsigned int)mib_build() == -1 )
exit(2);
if ( (unsigned int)mib_update(1LL) == -1 )
exit(2);
dump_mib(&g_mib, g_mib_length);
v4 = socket(10, 2, 0);
g_udp_sockfd = v4;
if ( v4 == -1 )
{
fprintf(stderr, "could not create UDP socket: %m\n");
exit(2);
}
*(_WORD *)addr = 10;
*(_WORD *)&addr[2] = func3(g_udp_port);
*(__m128i *)&addr[8] = _mm_loadu_si128((const __m128i *)&in6addr_any);
if ( bind(v4, (const struct sockaddr *)addr, 0x1Cu) == -1 )
{
fprintf(stderr, "could not bind UDP socket to port %d: %m\n", g_udp_port);
exit(2);
}
while ( !g_quit )
{
memset(&v9, 0, sizeof(v9));
v6 = g_udp_sockfd;
v9.fds_bits[g_udp_sockfd / 64] |= 1LL << (g_udp_sockfd % 64);
if ( select(v6 + 1, &v9, 0LL, 0LL, &timeout) == -1 )
{
if ( !g_quit )
{
fprintf(stderr, "could not select from sockets: %m\n");
exit(2);
}
break;
}
v7 = ticks_since(&tv, &v11);
v8 = v7;
if ( v7 < 0 || g_timeout <= v7 )
{
if ( g_verbose )
fwrite("updating the MIB (full)\n", 1uLL, 0x18uLL, stderr);
if ( (unsigned int)mib_update(1LL) == -1 )
exit(2);
tv = (struct timeval)_mm_loadu_si128(&v11);
timeout.tv_sec = g_timeout / 100;
timeout.tv_usec = 10000 * (g_timeout % 100);
}
else
{
if ( g_verbose )
fwrite("updating the MIB (partial)\n", 1uLL, 0x1BuLL, stderr);
if ( (unsigned int)mib_update(0LL) == -1 )
exit(2);
timeout.tv_sec = (g_timeout - v8) / 100;
timeout.tv_usec = 10000 * ((g_timeout - v8) % 100);
}
dump_mib(&g_mib, g_mib_length);
if ( (v9.fds_bits[g_udp_sockfd / 64] & (1LL << (g_udp_sockfd % 64))) != 0 )
func4();
}
fwrite("stopped\n", 1uLL, 8uLL, stderr);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 static const char short_options[] = "p:c:D:V:L:C:d:i:t:T:avlh";
 static const struct option long_options[] = {
  { "udp-port", 1, 0, 'p' },
  { "community", 1, 0, 'c' },
  { "description", 1, 0, 'D' },
  { "vendor", 1, 0, 'V' },
  { "location", 1, 0, 'L' },
  { "contact", 1, 0, 'C' },
  { "disks", 1, 0, 'd' },
  { "interfaces", 1, 0, 'i' },
  { "timeout", 1, 0, 't' },
  { "traps", 1, 0, 'T' },
  { "auth", 0, 0, 'a' },
  { "verbose", 0, 0, 'v' },
  { "licensing", 0, 0, 'l' },
  { "help", 0, 0, 'h' },
  { ((void *)0), 0, 0, 0 }
 };
 int option_index = 1;
 int c;
 struct sockaddr_in6 sockaddr;
 socklen_t socklen;
 struct timeval tv_last;
 struct timeval tv_now;
 struct timeval tv_sleep;
 int ticks;
 fd_set rfds;
 int nfds;
 signal(15, handle_signal);
 signal(1, handle_signal);
 siginterrupt(15, 0);
 siginterrupt(1, 0);
 while (1) {
  c = getopt_long(argc, argv, short_options, long_options, &option_index);
  if (c == -1) {
   break;
  }
  switch (c) {
   case 'p':
    g_udp_port = atoi(optarg);
    break;
   case 'c':
    g_community = strdup(optarg);
    break;
   case 'D':
    g_description = strdup(optarg);
    break;
   case 'V':
    g_vendor = strdup(optarg);
    break;
   case 'L':
    g_location = strdup(optarg);
    break;
   case 'C':
    g_contact = strdup(optarg);
    break;
   case 'd':
    g_disk_list_length = split(optarg, ",:;", g_disk_list, 4);
    break;
   case 'i':
    g_interface_list_length = split(optarg, ",:;", g_interface_list, 4);
    break;
   case 't':
    g_timeout = atoi(optarg) * 100;
    break;
   case 'a':
    g_auth = 1;
    break;
   case 'v':
    g_verbose = 1;
    break;
   case 'l':
    print_version();
    exit(1);
    break;
   default:
    print_help();
    exit(1);
  }
 }
 do { if (g_verbose || (6 != 7)) { fprintf(stderr, "started, listening on port %d/udp\n", g_udp_port); } } while (0);
 if (gettimeofday(&tv_last, ((void *)0)) == -1) {
  memset(&tv_last, 0, sizeof (tv_last));
  memset(&tv_sleep, 0, sizeof (&tv_sleep));
 } else {
  tv_sleep.tv_sec = g_timeout / 100;
  tv_sleep.tv_usec = (g_timeout % 100) * 10000;
 }
 if (mib_build() == -1) {
  exit(2);
 } else if (mib_update(1) == -1) {
  exit(2);
 }
 dump_mib(g_mib, g_mib_length);
 g_udp_sockfd = socket(10, SOCK_DGRAM, 0);
 if (g_udp_sockfd == -1) {
  do { if (g_verbose || (3 != 7)) { fprintf(stderr, "could not create UDP socket: %m\n"); } } while (0);
  exit(2);
 }
 sockaddr.sin6_family = 10;
 sockaddr.sin6_port = htons(g_udp_port);
 sockaddr.sin6_addr = in6addr_any;
 socklen = sizeof (sockaddr);
 if (bind(g_udp_sockfd, (struct sockaddr *)&sockaddr, socklen) == -1) {
  do { if (g_verbose || (3 != 7)) { fprintf(stderr, "could not bind UDP socket to port %d: %m\n", g_udp_port); } } while (0);
  exit(2);
 }
 while (!g_quit) {
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rfds)->fds_bits)[((g_udp_sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((g_udp_sockfd) % (8 * (int) sizeof (__fd_mask)))))));
  nfds = g_udp_sockfd;
  if (select(nfds + 1, &rfds, ((void *)0), ((void *)0), &tv_sleep) == -1) {
   if (g_quit) {
    break;
   }
   do { if (g_verbose || (3 != 7)) { fprintf(stderr, "could not select from sockets: %m\n"); } } while (0);
   exit(2);
  }
  ticks = ticks_since(&tv_last, &tv_now);
  if (ticks < 0 || ticks >= g_timeout) {
   do { if (g_verbose || (7 != 7)) { fprintf(stderr, "updating the MIB (full)\n"); } } while (0);
   if (mib_update(1) == -1) {
    exit(2);
   }
   memcpy(&tv_last, &tv_now, sizeof (tv_now));
   tv_sleep.tv_sec = g_timeout / 100;
   tv_sleep.tv_usec = (g_timeout % 100) * 10000;
  } else {
   do { if (g_verbose || (7 != 7)) { fprintf(stderr, "updating the MIB (partial)\n"); } } while (0);
   if (mib_update(0) == -1) {
    exit(2);
   }
   tv_sleep.tv_sec = (g_timeout - ticks) / 100;
   tv_sleep.tv_usec = ((g_timeout - ticks) % 100) * 10000;
  }
  dump_mib(g_mib, g_mib_length);
  if (((((&rfds)->fds_bits)[((g_udp_sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((g_udp_sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   handle_udp_client();
  }
 }
 do { if (g_verbose || (6 != 7)) { fprintf(stderr, "stopped\n"); } } while (0);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 static char short_options[] = "p:c:D:V:L:C:d:i:t:T:avlh";
 static struct option long_options[] = {
  { "udp-port", 1, 0, 'p' },
  { "community", 1, 0, 'c' },
  { "description", 1, 0, 'D' },
  { "vendor", 1, 0, 'V' },
  { "location", 1, 0, 'L' },
  { "contact", 1, 0, 'C' },
  { "disks", 1, 0, 'd' },
  { "interfaces", 1, 0, 'i' },
  { "timeout", 1, 0, 't' },
  { "traps", 1, 0, 'T' },
  { "auth", 0, 0, 'a' },
  { "verbose", 0, 0, 'v' },
  { "licensing", 0, 0, 'l' },
  { "help", 0, 0, 'h' },
  { ((void *)0), 0, 0, 0 }
 };
 int option_index = 1;
 int c;
 struct sockaddr_in6 sockaddr;
 unsigned int socklen;
 struct timeval tv_last;
 struct timeval tv_now;
 struct timeval tv_sleep;
 int ticks;
 struct fd_set rfds;
 int nfds;
 signal(15, handle_signal);
 signal(1, handle_signal);
 siginterrupt(15, 0);
 siginterrupt(1, 0);
 while (1) {
  c = getopt_long(argc, argv, short_options, long_options, &option_index);
  if (c == -1) {
   break;
  }
  switch (c) {
   case 'p':
    g_udp_port = atoi(optarg);
    break;
   case 'c':
    g_community = strdup(optarg);
    break;
   case 'D':
    g_description = strdup(optarg);
    break;
   case 'V':
    g_vendor = strdup(optarg);
    break;
   case 'L':
    g_location = strdup(optarg);
    break;
   case 'C':
    g_contact = strdup(optarg);
    break;
   case 'd':
    g_disk_list_length = split(optarg, ",:;", g_disk_list, 4);
    break;
   case 'i':
    g_interface_list_length = split(optarg, ",:;", g_interface_list, 4);
    break;
   case 't':
    g_timeout = atoi(optarg) * 100;
    break;
   case 'a':
    g_auth = 1;
    break;
   case 'v':
    g_verbose = 1;
    break;
   case 'l':
    print_version();
    exit(1);
    break;
   default:
    print_help();
    exit(1);
  }
 }
 do { if (g_verbose || (6 != 7)) { fprintf(stderr, "started, listening on port %d/udp\n", g_udp_port); } } while (0);
 if (gettimeofday(&tv_last, ((void *)0)) == -1) {
  memset(&tv_last, 0, sizeof (tv_last));
  memset(&tv_sleep, 0, sizeof (&tv_sleep));
 } else {
  tv_sleep.tv_sec = g_timeout / 100;
  tv_sleep.tv_usec = (g_timeout % 100) * 10000;
 }
 if (mib_build() == -1) {
  exit(2);
 } else if (mib_update(1) == -1) {
  exit(2);
 }
 dump_mib(g_mib, g_mib_length);
 g_udp_sockfd = socket(10, SOCK_DGRAM, 0);
 if (g_udp_sockfd == -1) {
  do { if (g_verbose || (3 != 7)) { fprintf(stderr, "could not create UDP socket: %m\n"); } } while (0);
  exit(2);
 }
 sockaddr.sin6_family = 10;
 sockaddr.sin6_port = htons(g_udp_port);
 sockaddr.sin6_addr = in6addr_any;
 socklen = sizeof (sockaddr);
 if (bind(g_udp_sockfd, (struct sockaddr *)&sockaddr, socklen) == -1) {
  do { if (g_verbose || (3 != 7)) { fprintf(stderr, "could not bind UDP socket to port %d: %m\n", g_udp_port); } } while (0);
  exit(2);
 }
 while (!g_quit) {
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rfds)->fds_bits)[((g_udp_sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((g_udp_sockfd) % (8 * (int) sizeof (__fd_mask)))))));
  nfds = g_udp_sockfd;
  if (select(nfds + 1, &rfds, ((void *)0), ((void *)0), &tv_sleep) == -1) {
   if (g_quit) {
    break;
   }
   do { if (g_verbose || (3 != 7)) { fprintf(stderr, "could not select from sockets: %m\n"); } } while (0);
   exit(2);
  }
  ticks = ticks_since(&tv_last, &tv_now);
  if (ticks < 0 || ticks >= g_timeout) {
   do { if (g_verbose || (7 != 7)) { fprintf(stderr, "updating the MIB (full)\n"); } } while (0);
   if (mib_update(1) == -1) {
    exit(2);
   }
   memcpy(&tv_last, &tv_now, sizeof (tv_now));
   tv_sleep.tv_sec = g_timeout / 100;
   tv_sleep.tv_usec = (g_timeout % 100) * 10000;
  } else {
   do { if (g_verbose || (7 != 7)) { fprintf(stderr, "updating the MIB (partial)\n"); } } while (0);
   if (mib_update(0) == -1) {
    exit(2);
   }
   tv_sleep.tv_sec = (g_timeout - ticks) / 100;
   tv_sleep.tv_usec = ((g_timeout - ticks) % 100) * 10000;
  }
  dump_mib(g_mib, g_mib_length);
  if (((((&rfds)->fds_bits)[((g_udp_sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((g_udp_sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   handle_udp_client();
  }
 }
 do { if (g_verbose || (6 != 7)) { fprintf(stderr, "stopped\n"); } } while (0);
 return 0;
}

variable_types:
argv
char *[]

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

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

variable_types: ticks int

variable_types:
rfds
struct fd_set { long fds_bits[-1]; }

variable_types: nfds int

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


decompiled_code:
__int64 __fastcall read_value(const char *a1, const char *a2)
{
char *v2; // rax
unsigned int v3; // edx
const char *v4; // rbx
const unsigned __int16 *v5; // rcx

v2 = strstr(a1, a2);
v3 = 0;
if ( v2 )
{
v4 = &v2[strlen(a2)];
v5 = *_ctype_b_loc();
while ( (v5[*v4] & 0x2000) != 0 )
++v4;
v3 = 0;
if ( *v4 )
v3 = strtoul(v4, 0LL, 0);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
char *v2; // rax
unsigned int v3; // edx
const char *v4; // rbx
const unsigned __int16 *v5; // rcx

v2 = strstr(a1, a2);
v3 = 0;
if ( v2 )
{
v4 = &v2[strlen(a2)];
v5 = *_ctype_b_loc();
while ( (v5[*v4] & 0x2000) != 0 )
++v4;
v3 = 0;
if ( *v4 )
v3 = strtoul(v4, 0LL, 0);
}
return v3;
}

original_code:
unsigned int read_value(const char *buffer, const char *prefix)
{
 buffer = strstr(buffer, prefix);
 if (buffer != ((void *)0)) {
  buffer += strlen(prefix);
  while (((*__ctype_b_loc ())[(int) ((*buffer))] & (unsigned short int) _ISspace)) {
   buffer++;
  }
  return (*buffer != '\0') ? strtoul(buffer, ((void *)0), 0) : 0;
 } else {
  return 0;
 }
}

canonical_original_code:
unsigned int read_value(char *buffer, char *prefix)
{
 buffer = strstr(buffer, prefix);
 if (buffer != ((void *)0)) {
  buffer += strlen(prefix);
  while (((*__ctype_b_loc ())[(int) ((*buffer))] & (unsigned short) _ISspace)) {
   buffer++;
  }
  return (*buffer != '\0') ? strtoul(buffer, ((void *)0), 0) : 0;
 } else {
  return 0;
 }
}

variable_types:
buffer
char *

variable_types:
prefix
char *


decompiled_code:
size_t __fastcall read_values(const char *a1, const char *a2, void *a3, int a4)
{
char *v6; // rax
char *v7; // rbx
size_t result; // rax
_DWORD *v9; // rbx
__int64 v10; // r12
const unsigned __int16 **v11; // rbp
const unsigned __int16 *v12; // rcx
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v6 = strstr(a1, a2);
endptr = v6;
if ( !v6 )
return (size_t)memset(a3, 0, 4LL * a4);
v7 = v6;
result = strlen(a2);
endptr = &v7[result];
if ( a4 > 0 )
{
v9 = a3;
v10 = (__int64)a3 + 4 * (unsigned int)(a4 - 1) + 4;
v11 = _ctype_b_loc();
do
{
v12 = *v11;
while ( 1 )
{
result = (unsigned __int8)*endptr;
if ( (v12[(char)result] & 0x2000) == 0 )
break;
++endptr;
}
if ( (_BYTE)result )
{
result = strtoul(endptr, &endptr, 0);
*v9 = result;
}
else
{
*v9 = 0;
}
++v9;
}
while ( v9 != (_DWORD *)v10 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(const char *a1, const char *a2, void *a3, int a4)
{
char *v6; // rax
char *v7; // rbx
size_t result; // rax
_DWORD *v9; // rbx
__int64 v10; // r12
const unsigned __int16 **v11; // rbp
const unsigned __int16 *v12; // rcx
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v6 = strstr(a1, a2);
endptr = v6;
if ( !v6 )
return (size_t)memset(a3, 0, 4LL * a4);
v7 = v6;
result = strlen(a2);
endptr = &v7[result];
if ( a4 > 0 )
{
v9 = a3;
v10 = (__int64)a3 + 4 * (unsigned int)(a4 - 1) + 4;
v11 = _ctype_b_loc();
do
{
v12 = *v11;
while ( 1 )
{
result = (unsigned __int8)*endptr;
if ( (v12[(char)result] & 0x2000) == 0 )
break;
++endptr;
}
if ( (_BYTE)result )
{
result = strtoul(endptr, &endptr, 0);
*v9 = result;
}
else
{
*v9 = 0;
}
++v9;
}
while ( v9 != (_DWORD *)v10 );
}
return result;
}

original_code:
void read_values(const char *buffer, const char *prefix, unsigned int *values, int count)
{
 int i;
 buffer = strstr(buffer, prefix);
 if (buffer != ((void *)0)) {
  buffer += strlen(prefix);
  for (i = 0; i < count; i++) {
   while (((*__ctype_b_loc ())[(int) ((*buffer))] & (unsigned short int) _ISspace)) {
    buffer++;
   }
   if (*buffer != '\0') {
    values[i] = strtoul(buffer, (char **)&buffer, 0);
   } else {
    values[i] = 0;
   }
  }
 } else {
  memset(values, 0, count * sizeof (unsigned int));
 }
}

canonical_original_code:
void read_values(char *buffer, char *prefix, unsigned int *values, int count)
{
 int i;
 buffer = strstr(buffer, prefix);
 if (buffer != ((void *)0)) {
  buffer += strlen(prefix);
  for (i = 0; i < count; i++) {
   while (((*__ctype_b_loc ())[(int) ((*buffer))] & (unsigned short) _ISspace)) {
    buffer++;
   }
   if (*buffer != '\0') {
    values[i] = strtoul(buffer, (char **)&buffer, 0);
   } else {
    values[i] = 0;
   }
  }
 } else {
  memset(values, 0, count * sizeof (unsigned int));
 }
}

variable_types:
values
unsigned int *

variable_types: count int

variable_types: i int