htonQuit

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

htonHeader(*(_DWORD *)a1, (__int16 *)a2);
htonProxyInfo(a1 + 4, a2 + 4);
result = htonll(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a2 + 16) = result;
return result;
}

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

func2(*(_DWORD *)a1, (__int16 *)a2);
func3(a1 + 4, a2 + 4);
result = htonll(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a2 + 16) = result;
return result;
}

original_code:
void htonQuit(quit_pkt* pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    htonProxyInfo(&pkt->local,buffer+4);
    uint64_t ID;
    ID = htonll(pkt->ID);
    memcpy(buffer+16,&ID,8);
}

canonical_original_code:
void htonQuit(struct quit_pkt *pkt, char *buffer) {
    htonHeader(pkt->head, buffer);
    htonProxyInfo(&pkt->local,buffer+4);
    unsigned long ID;
    ID = htonll(pkt->ID);
    memcpy(buffer+16,&ID,8);
}

variable_types: struct quit_pkt { struct pkt_header { unsigned short type; unsigned short length; } head; struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } local; unsigned long ID; } *

user_defined_types: struct quit_pkt { struct pkt_header head; struct proxy_info local; unsigned long ID; }


ntohQuit

decompiled_code:
char *__fastcall ntohQuit(__int64 a1)
{
char *v1; // rbx
_WORD *v2; // r13
_WORD *v3; // rbp

v1 = (char *)malloc(0x18uLL);
v2 = ntohHeader((__int16 *)a1);
*(_DWORD *)v1 = *(_DWORD *)v2;
v3 = ntohProxyInfo(a1 + 4);
*(_QWORD *)(v1 + 4) = *(_QWORD *)v3;
*((_DWORD *)v1 + 3) = *((_DWORD *)v3 + 2);
*((_QWORD *)v1 + 2) = htonll(*(_QWORD *)(a1 + 16));
free(v2);
free(v3);
return v1;
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1)
{
char *v1; // rbx
_WORD *v2; // r13
_WORD *v3; // rbp

v1 = (char *)malloc(0x18uLL);
v2 = ntohHeader((__int16 *)a1);
*(_DWORD *)v1 = *(_DWORD *)v2;
v3 = ntohProxyInfo(a1 + 4);
*(_QWORD *)(v1 + 4) = *(_QWORD *)v3;
*((_DWORD *)v1 + 3) = *((_DWORD *)v3 + 2);
*((_QWORD *)v1 + 2) = htonll(*(_QWORD *)(a1 + 16));
free(v2);
free(v3);
return v1;
}

original_code:
quit_pkt* ntohQuit(char *buffer) {
    quit_pkt* pkt = malloc(sizeof(quit_pkt));
    pkt_header* head = ntohHeader(buffer);
    pkt->head = *head;
    proxy_info* local = ntohProxyInfo(buffer+4);
    pkt->local = *local;
    uint64_t ID;
    ID = htonll(*(uint64_t*)(buffer+16));
    pkt->ID = ID;
    free(head);
    free(local);
    return pkt;
}

canonical_original_code:
struct quit_pkt *ntohQuit(char *buffer) {
    struct quit_pkt *pkt = malloc(sizeof(quit_pkt));
    struct pkt_header *head = ntohHeader(buffer);
    pkt->head = *head;
    struct proxy_info *local = ntohProxyInfo(buffer+4);
    pkt->local = *local;
    unsigned long ID;
    ID = htonll(*(unsigned long *)(buffer+16));
    pkt->ID = ID;
    free(head);
    free(local);
    return pkt;
}

variable_types:
buffer
char *

variable_types: struct pkt_header { unsigned short type; unsigned short length; } *

variable_types: struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } *

variable_types:
ID
unsigned long

return_type: struct quit_pkt { struct pkt_header { unsigned short type; unsigned short length; } head; struct proxy_info { unsigned int ip; unsigned short portno; unsigned char macaddr[6]; } local; unsigned long ID; } *


gettimeid

decompiled_code:
__time_t gettimeid()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

canonical_decompiled_code:
__time_t func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

original_code:
unsigned long gettimeid(void) {
    struct timeval tim;
    gettimeofday(&tim, ((void *)0));
    return (tim.tv_sec) * 1000 + (tim.tv_usec)/1000;
}

canonical_original_code:
unsigned long gettimeid() {
    struct timeval tim;
    gettimeofday(&tim, ((void *)0));
    return (tim.tv_sec) * 1000 + (tim.tv_usec)/1000;
}

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

return_type: unsigned long


htonll

decompiled_code:
unsigned __int64 __fastcall htonll(unsigned __int64 a1)
{
unsigned __int64 v1; // rax
unsigned __int64 result; // rax

if ( !typ_0 )
{
typ_0 = 1;
LABEL_3:
v1 = (a1 << 56) | HIBYTE(a1);
BYTE1(v1) = BYTE6(a1);
return ((unsigned __int64)BYTE3(a1) << 32) | ((a1 >> 8) & 0xFF000000 | (((unsigned __int64)BYTE2(a1) << 40) | ((a1 >> 24) & 0xFF0000 | (((unsigned __int64)BYTE1(a1) << 48) | v1 & 0xFF00FFFFFFFFFFFFLL) & 0xFFFFFFFFFF00FFFFLL) & 0xFFFF00FFFFFFFFFFLL) & 0xFFFFFFFF00FFFFFFLL) & 0xFFFFFF00FFFFFFFFLL;
}
result = a1;
if ( typ_0 != 2 )
goto LABEL_3;
return result;
}

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

if ( !typ_0 )
{
typ_0 = 1;
LABEL_3:
v1 = (a1 << 56) | HIBYTE(a1);
BYTE1(v1) = BYTE6(a1);
return ((unsigned __int64)BYTE3(a1) << 32) | ((a1 >> 8) & 0xFF000000 | (((unsigned __int64)BYTE2(a1) << 40) | ((a1 >> 24) & 0xFF0000 | (((unsigned __int64)BYTE1(a1) << 48) | v1 & 0xFF00FFFFFFFFFFFFLL) & 0xFFFFFFFFFF00FFFFLL) & 0xFFFF00FFFFFFFFFFLL) & 0xFFFFFFFF00FFFFFFLL) & 0xFFFFFF00FFFFFFFFLL;
}
result = a1;
if ( typ_0 != 2 )
goto LABEL_3;
return result;
}

original_code:
unsigned long long htonll(unsigned long long src) {
  static int typ = 0;
  unsigned char c;
  union {
    unsigned long long ull;
    unsigned char c[8];
  } x;
  if (typ == 0) {
    x.ull = 0x01;
    typ = (x.c[7] == 0x01ULL) ? 2 : 1;
  }
  if (typ == 2)
    return src;
  x.ull = src;
  c = x.c[0]; x.c[0] = x.c[7]; x.c[7] = c;
  c = x.c[1]; x.c[1] = x.c[6]; x.c[6] = c;
  c = x.c[2]; x.c[2] = x.c[5]; x.c[5] = c;
  c = x.c[3]; x.c[3] = x.c[4]; x.c[4] = c;
  return x.ull;
}

variable_types:
src
unsigned long long

variable_types: typ int

variable_types:
c
unsigned char

return_type: unsigned long long


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

v2 = 0LL;
while ( *(_BYTE *)(a1 + v2) == *(_BYTE *)(a2 + v2) )
{
if ( ++v2 == 6 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

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

v2 = 0LL;
while ( *(_BYTE *)(a1 + v2) == *(_BYTE *)(a2 + v2) )
{
if ( ++v2 == 6 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int comp_mac_addrs(uint8_t* mac1, uint8_t* mac2) {
    int i = 0;
    for (i = 0; i < 6; i++) {
        if (mac1[i] != mac2[i]) {
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int comp_mac_addrs(unsigned char *mac1, unsigned char *mac2) {
    int i = 0;
    for (i = 0; i < 6; i++) {
        if (mac1[i] != mac2[i]) {
            return -1;
        }
    }
    return 0;
}

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall comp_mac_zero(_BYTE *a1)
{
_BYTE *v1; // rax

v1 = a1 + 6;
while ( !*a1 )
{
if ( ++a1 == v1 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1)
{
_BYTE *v1; // rax

v1 = a1 + 6;
while ( !*a1 )
{
if ( ++a1 == v1 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
int comp_mac_zero(uint8_t* mac1) {
    int i = 0;
    for (i = 0; i < 6; i++) {
        if (mac1[i] != 0) {
            return 0;
        }
    }
    return -1;
}

canonical_original_code:
int comp_mac_zero(unsigned char *mac1) {
    int i = 0;
    for (i = 0; i < 6; i++) {
        if (mac1[i] != 0) {
            return 0;
        }
    }
    return -1;
}


decompiled_code:
__int64 __fastcall ref_init(int a1, unsigned __int8 a2, int a3, unsigned __int8 *a4)
{
int v4; // ebx
unsigned __int8 *v5; // rsi
int v6; // edi
__int64 result; // rax
__int64 v8; // rdx

ref_a = a1;
ref_r = a2;
ref_c = a3;
v4 = a2;
if ( a2 <= 3u )
{
result = 0LL;
}
else
{
v5 = a4;
v6 = 0;
do
{
ref_state[v6 >> 2] = (v5[1] << 8) + (v5[2] << 16) + *v5 + (v5[3] << 24);
v6 += 4;
v5 += 4;
}
while ( v6 != ((v4 - 4) & 0xFFFFFFFC) + 4 );
result = 4 * ((unsigned int)(v4 - 4) >> 2) + 4;
}
if ( v4 > (int)result )
ref_state[(int)result >> 2] = a4[(int)result];
if ( (int)result + 1 < v4 )
ref_state[(int)result >> 2] += a4[(int)result + 1] << 8;
if ( (int)result + 2 < v4 )
{
v8 = (int)result >> 2;
result = a4[(int)result + 2] << 16;
ref_state[v8] += result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, unsigned __int8 a2, int a3, unsigned __int8 *a4)
{
int v4; // ebx
unsigned __int8 *v5; // rsi
int v6; // edi
__int64 result; // rax
__int64 v8; // rdx

ref_a = a1;
ref_r = a2;
ref_c = a3;
v4 = a2;
if ( a2 <= 3u )
{
result = 0LL;
}
else
{
v5 = a4;
v6 = 0;
do
{
ref_state[v6 >> 2] = (v5[1] << 8) + (v5[2] << 16) + *v5 + (v5[3] << 24);
v6 += 4;
v5 += 4;
}
while ( v6 != ((v4 - 4) & 0xFFFFFFFC) + 4 );
result = 4 * ((unsigned int)(v4 - 4) >> 2) + 4;
}
if ( v4 > (int)result )
ref_state[(int)result >> 2] = a4[(int)result];
if ( (int)result + 1 < v4 )
ref_state[(int)result >> 2] += a4[(int)result + 1] << 8;
if ( (int)result + 2 < v4 )
{
v8 = (int)result >> 2;
result = a4[(int)result + 2] << 16;
ref_state[v8] += result;
}
return result;
}

original_code:
static void ref_init(uint32_t a, uint8_t r, uint32_t c, uint8_t const *seed)
{
    int i;
    ref_a = a;
    ref_r = r;
    ref_c = c;
    for (i = 0; i + 3 < r; i += 4)
        ref_state[i >> 2] = seed[i] + ((uint32_t)seed[i + 1] << 8) + ((uint32_t)seed[i + 2] << 16) + ((uint32_t)seed[i + 3] << 24);
    if (i < r) ref_state[i >> 2] = seed[i];
    if (i + 1 < r) ref_state[i >> 2] += (uint32_t)seed[i + 1] << 8;
    if (i + 2 < r) ref_state[i >> 2] += (uint32_t)seed[i + 2] << 16;
}

canonical_original_code:
static void ref_init(unsigned int a, unsigned char r, unsigned int c, unsigned char *seed)
{
    int i;
    ref_a = a;
    ref_r = r;
    ref_c = c;
    for (i = 0; i + 3 < r; i += 4)
        ref_state[i >> 2] = seed[i] + ((unsigned int)seed[i + 1] << 8) + ((unsigned int)seed[i + 2] << 16) + ((unsigned int)seed[i + 3] << 24);
    if (i < r) ref_state[i >> 2] = seed[i];
    if (i + 1 < r) ref_state[i >> 2] += (unsigned int)seed[i + 1] << 8;
    if (i + 2 < r) ref_state[i >> 2] += (unsigned int)seed[i + 2] << 16;
}

variable_types:
a
unsigned int

variable_types:
r
unsigned char

variable_types:
c
unsigned int

variable_types:
seed
unsigned char *

return_type: void


original_code:
static void dut_memrand(uint8_t *dst, int length, uint16_t (*genfn)(void))
{
    int i;
    uint8_t *p = dst;
    for (i = 0; i < length; i += 2)
    {
        uint16_t x = genfn();
        *p++ = x & 0xff;
        *p++ = x >> 8;
    }
}

canonical_original_code:
static void dut_memrand(unsigned char *dst, int length, unsigned short (*genfn)())
{
    int i;
    unsigned char *p = dst;
    for (i = 0; i < length; i += 2)
    {
        unsigned short x = genfn();
        *p++ = x & 0xff;
        *p++ = x >> 8;
    }
}

variable_types:
dst
unsigned char *

variable_types: length int

variable_types:
genfn
unsigned short (*)()

variable_types:
p
unsigned char *

variable_types:
x
unsigned short


original_code:
static void ref_memtest(uint8_t const *src, int length, uint64_t count)
{
    unsigned int a = ref_a;
    unsigned int c = ref_c;
    int r = ref_r;
    int i, j;
    for (i = 0; i < length; i += r)
    {
        for (j = 0; j < r; j += 4)
        {
            uint32_t dut;
            uint32_t x = ref_state[j >> 2];
            uint64_t t;
            int bits;
            t = (uint64_t)x * a + c;
            bits = (r - j) * 8;
            if (bits >= 32)
            {
                bits = 32;
                x = (uint32_t)t;
                dut = src[0] + ((uint32_t)src[1] << 8) + ((uint32_t)src[2] << 16) + ((uint32_t)src[3] << 24);
                src += 4;
            }
            else
            {
                x = (uint32_t)t & ~(0xffffffff << bits);
                dut = *src++;
                if (bits > 8) dut += (uint32_t)*src++ << 8;
                if (bits > 16) dut += (uint32_t)*src++ << 16;
            }
            if (dut != x)
            {
                fprintf(stderr, "0x%llx: 0x%08x != 0x%08x\n", count + i+j, dut, x);
                fprintf(stderr, "t=0x%010llx=(a=0x%04x * s[%d]=0x%08x + c=0x%04x)\n", t, a, j, ref_state[j >> 2], c);
                exit(1);
            }
            c = (uint32_t)(t >> bits);
            ref_state[j >> 2] = x;
        }
    }
    ref_c = c;
}

canonical_original_code:
static void ref_memtest(unsigned char *src, int length, unsigned long count)
{
    unsigned int a = ref_a;
    unsigned int c = ref_c;
    int r = ref_r;
    int i; int j;
    for (i = 0; i < length; i += r)
    {
        for (j = 0; j < r; j += 4)
        {
            unsigned int dut;
            unsigned int x = ref_state[j >> 2];
            unsigned long t;
            int bits;
            t = (unsigned long)x * a + c;
            bits = (r - j) * 8;
            if (bits >= 32)
            {
                bits = 32;
                x = (unsigned int)t;
                dut = src[0] + ((unsigned int)src[1] << 8) + ((unsigned int)src[2] << 16) + ((unsigned int)src[3] << 24);
                src += 4;
            }
            else
            {
                x = (unsigned int)t & ~(0xffffffff << bits);
                dut = *src++;
                if (bits > 8) dut += (unsigned int)*src++ << 8;
                if (bits > 16) dut += (unsigned int)*src++ << 16;
            }
            if (dut != x)
            {
                fprintf(stderr, "0x%llx: 0x%08x != 0x%08x\n", count + i+j, dut, x);
                fprintf(stderr, "t=0x%010llx=(a=0x%04x * s[%d]=0x%08x + c=0x%04x)\n", t, a, j, ref_state[j >> 2], c);
                exit(1);
            }
            c = (unsigned int)(t >> bits);
            ref_state[j >> 2] = x;
        }
    }
    ref_c = c;
}

variable_types:
src
unsigned char *

variable_types:
count
unsigned long

variable_types: r int

variable_types: j int

variable_types:
dut
unsigned int

variable_types:
x
unsigned int

variable_types:
t
unsigned long

variable_types: bits int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // bp
int v4; // eax
unsigned __int64 v5; // rax
char *v6; // rbp
__int64 v7; // rbx
unsigned __int8 v8; // al
__int64 *v9; // rax
char *v11; // rax
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // rax
void *v15; // r13
__int64 *v16; // rbx
const char **v17; // rax
const char *v18; // rax
unsigned __int64 v19; // rdi
const char *v20; // rax
unsigned __int64 v21; // rdi
__int64 v22; // [rsp+8h] [rbp-90h]
char *v23; // [rsp+10h] [rbp-88h]
unsigned int v24; // [rsp+1Ch] [rbp-7Ch]
char *v25; // [rsp+20h] [rbp-78h]
unsigned __int8 v26; // [rsp+29h] [rbp-6Fh]
unsigned __int16 v27; // [rsp+2Ah] [rbp-6Eh]
int v28; // [rsp+2Ch] [rbp-6Ch]
int v29; // [rsp+3Ch] [rbp-5Ch] BYREF
__int64 v30[11]; // [rsp+40h] [rbp-58h] BYREF

v30[0] = 0LL;
v30[1] = 0LL;
v30[2] = 0LL;
v30[3] = 0LL;
v22 = 0LL;
v23 = 0LL;
v28 = 0;
v25 = 0LL;
v3 = 0;
v26 = 0;
v27 = 1;
v24 = 0;
LABEL_2:
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "e:W:w:n:u:a:r:s:c:gth");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'W':
v22 = strtol(optarg, 0LL, 0);
v23 = (char *)&multiplier_table;
continue;
case 'a':
v24 = strtoul(optarg, 0LL, 0);
continue;
case 'c':
v27 = strtoul(optarg, 0LL, 0);
continue;
case 'e':
v5 = strtol(optarg, 0LL, 0);
if ( v5 > 5 )
{
fprintf(stderr, "Only %d known example functions.\n", 6LL);
exit(1);
}
v25 = (char *)&examples + 40 * v5;
v24 = *((_DWORD *)&examples + 10 * v5 + 4);
v26 = *((_BYTE *)&examples + 40 * v5 + 20);
continue;
case 'g':
v28 = 0;
continue;
case 'h':
usage();
return 0;
case 'n':
v22 = strtol(optarg, 0LL, 0);
v23 = (char *)&multiplier_table + 1056;
continue;
case 'r':
v26 = strtoul(optarg, 0LL, 0);
continue;
case 's':
v6 = optarg;
if ( !strncasecmp(optarg, "0x", 2uLL) )
v6 += 2;
v7 = 0LL;
break;
case 't':
v28 = 1;
continue;
case 'u':
v22 = strtol(optarg, 0LL, 0);
v23 = (char *)&multiplier_table + 1584;
continue;
case 'w':
v22 = strtol(optarg, 0LL, 0);
v23 = (char *)&multiplier_table + 528;
continue;
default:
fwrite("Invalid argument.\n", 1uLL, 0x12uLL, stderr);
usage();
exit(1);
}
while ( (unsigned int)_isoc99_sscanf(v6, "%02x", &v29) == 1 )
{
*((_BYTE *)v30 + v7) = v29;
v6 += 2;
v8 = ++v7;
if ( v7 == 32 )
{
v3 = v8;
goto LABEL_2;
}
}
v3 = v7;
if ( (unsigned int)v7 <= 0x1F )
{
v9 = (__int64 *)((char *)v30 + (int)v7);
do
{
*(_BYTE *)v9 = 0;
v9 = (__int64 *)((char *)v9 + 1);
}
while ( v9 != (__int64 *)((char *)v30 + (int)v7 + (unsigned int)(31 - v7) + 1) );
}
}
if ( (unsigned __int8)(v26 - 1) > 0x1Fu )
{
fwrite("Out-of-range lag value.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( !v24 )
{
if ( !v23 )
{
fwrite("Must choose multiplier.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( v22 < 0 )
v22 += *(int *)&v23[16 * v26];
v11 = &v23[16 * v26];
v12 = *(unsigned int *)v11;
if ( (unsigned int)v12 <= (unsigned int)v22 )
{
if ( (int)v12 <= 0 )
fprintf(stderr, "No known lag-%d multipliers.\n", v26);
else
fprintf(stderr, "Only %d known lag-%d multipliers.\n", v12, v26);
exit(1);
}
v24 = *(_DWORD *)(*((_QWORD *)v11 + 1) + 4 * v22);
}
if ( v25 )
{
(*(void (__fastcall **)(__int64 *, _QWORD))v25)(v30, v3);
v13 = *((_QWORD *)v25 + 3);
v14 = 0LL;
do
{
*((_BYTE *)v30 + v14) = *(_BYTE *)(v13 + v14);
++v14;
}
while ( v26 > (int)v14 );
v27 = **((_WORD **)v25 + 4);
v15 = (void *)*((_QWORD *)v25 + 1);
}
else
{
rand8_init((unsigned __int16)v24, v26, v27, v30);
if ( (unsigned __int16)(v24 >> 8) )
{
v15 = &rand16_9bit;
if ( (unsigned __int16)(v24 >> 8) != 1 )
{
v15 = &rand16_16bit;
if ( !BYTE1(v24) )
{
rand8_init((unsigned __int16)((v24 >> 8) | (unsigned __int8)v24), v26, v27, v30);
v15 = &rand16_8z8bit;
}
}
}
else
{
v15 = &rand16_8bit;
}
}
fprintf(stderr, "b=256 a=0x%04x r=%d c=0x%04x s=0x", v24, v26, v27);
v16 = v30;
do
{
fprintf(stderr, "%02x", *(unsigned __int8 *)v16);
v16 = (__int64 *)((char *)v16 + 1);
}
while ( (__int64 *)((char *)v30 + v26) != v16 );
fputc(10, stderr);
if ( (unsigned __int16)v24 + 255 * (unsigned int)(unsigned __int8)v24 - 1 > 0xFFFF )
{
fwrite("This multiplier could overflow internal arithmetic.\n", 1uLL, 0x34uLL, stderr);
exit(1);
}
v17 = &argv[optind];
if ( v28 )
{
v18 = *v17;
v19 = 0x40000000LL;
if ( v18 )
v19 = strtoull(v18, 0LL, 0);
test_loop(v19, v15, v24, v26, v27, v30);
}
else
{
v20 = *v17;
v21 = -1LL;
if ( v20 )
v21 = strtoull(v20, 0LL, 0);
generate_loop(v21, v15);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // bp
int v4; // eax
unsigned __int64 v5; // rax
char *v6; // rbp
__int64 v7; // rbx
unsigned __int8 v8; // al
__int64 *v9; // rax
char *v11; // rax
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // rax
void *v15; // r13
__int64 *v16; // rbx
const char **v17; // rax
const char *v18; // rax
unsigned __int64 v19; // rdi
const char *v20; // rax
unsigned __int64 v21; // rdi
__int64 v22; // [rsp+8h] [rbp-90h]
char *v23; // [rsp+10h] [rbp-88h]
unsigned int v24; // [rsp+1Ch] [rbp-7Ch]
char *v25; // [rsp+20h] [rbp-78h]
unsigned __int8 v26; // [rsp+29h] [rbp-6Fh]
unsigned __int16 v27; // [rsp+2Ah] [rbp-6Eh]
int v28; // [rsp+2Ch] [rbp-6Ch]
int v29; // [rsp+3Ch] [rbp-5Ch] BYREF
__int64 v30[11]; // [rsp+40h] [rbp-58h] BYREF

v30[0] = 0LL;
v30[1] = 0LL;
v30[2] = 0LL;
v30[3] = 0LL;
v22 = 0LL;
v23 = 0LL;
v28 = 0;
v25 = 0LL;
v3 = 0;
v26 = 0;
v27 = 1;
v24 = 0;
LABEL_2:
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "e:W:w:n:u:a:r:s:c:gth");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'W':
v22 = strtol(optarg, 0LL, 0);
v23 = (char *)&multiplier_table;
continue;
case 'a':
v24 = strtoul(optarg, 0LL, 0);
continue;
case 'c':
v27 = strtoul(optarg, 0LL, 0);
continue;
case 'e':
v5 = strtol(optarg, 0LL, 0);
if ( v5 > 5 )
{
fprintf(stderr, "Only %d known example functions.\n", 6LL);
exit(1);
}
v25 = (char *)&examples + 40 * v5;
v24 = *((_DWORD *)&examples + 10 * v5 + 4);
v26 = *((_BYTE *)&examples + 40 * v5 + 20);
continue;
case 'g':
v28 = 0;
continue;
case 'h':
func3();
return 0;
case 'n':
v22 = strtol(optarg, 0LL, 0);
v23 = (char *)&multiplier_table + 1056;
continue;
case 'r':
v26 = strtoul(optarg, 0LL, 0);
continue;
case 's':
v6 = optarg;
if ( !strncasecmp(optarg, "0x", 2uLL) )
v6 += 2;
v7 = 0LL;
break;
case 't':
v28 = 1;
continue;
case 'u':
v22 = strtol(optarg, 0LL, 0);
v23 = (char *)&multiplier_table + 1584;
continue;
case 'w':
v22 = strtol(optarg, 0LL, 0);
v23 = (char *)&multiplier_table + 528;
continue;
default:
fwrite("Invalid argument.\n", 1uLL, 0x12uLL, stderr);
func3();
exit(1);
}
while ( (unsigned int)_isoc99_sscanf(v6, "%02x", &v29) == 1 )
{
*((_BYTE *)v30 + v7) = v29;
v6 += 2;
v8 = ++v7;
if ( v7 == 32 )
{
v3 = v8;
goto LABEL_2;
}
}
v3 = v7;
if ( (unsigned int)v7 <= 0x1F )
{
v9 = (__int64 *)((char *)v30 + (int)v7);
do
{
*(_BYTE *)v9 = 0;
v9 = (__int64 *)((char *)v9 + 1);
}
while ( v9 != (__int64 *)((char *)v30 + (int)v7 + (unsigned int)(31 - v7) + 1) );
}
}
if ( (unsigned __int8)(v26 - 1) > 0x1Fu )
{
fwrite("Out-of-range lag value.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( !v24 )
{
if ( !v23 )
{
fwrite("Must choose multiplier.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( v22 < 0 )
v22 += *(int *)&v23[16 * v26];
v11 = &v23[16 * v26];
v12 = *(unsigned int *)v11;
if ( (unsigned int)v12 <= (unsigned int)v22 )
{
if ( (int)v12 <= 0 )
fprintf(stderr, "No known lag-%d multipliers.\n", v26);
else
fprintf(stderr, "Only %d known lag-%d multipliers.\n", v12, v26);
exit(1);
}
v24 = *(_DWORD *)(*((_QWORD *)v11 + 1) + 4 * v22);
}
if ( v25 )
{
(*(void (__fastcall **)(__int64 *, _QWORD))v25)(v30, v3);
v13 = *((_QWORD *)v25 + 3);
v14 = 0LL;
do
{
*((_BYTE *)v30 + v14) = *(_BYTE *)(v13 + v14);
++v14;
}
while ( v26 > (int)v14 );
v27 = **((_WORD **)v25 + 4);
v15 = (void *)*((_QWORD *)v25 + 1);
}
else
{
rand8_init((unsigned __int16)v24, v26, v27, v30);
if ( (unsigned __int16)(v24 >> 8) )
{
v15 = &rand16_9bit;
if ( (unsigned __int16)(v24 >> 8) != 1 )
{
v15 = &rand16_16bit;
if ( !BYTE1(v24) )
{
rand8_init((unsigned __int16)((v24 >> 8) | (unsigned __int8)v24), v26, v27, v30);
v15 = &rand16_8z8bit;
}
}
}
else
{
v15 = &rand16_8bit;
}
}
fprintf(stderr, "b=256 a=0x%04x r=%d c=0x%04x s=0x", v24, v26, v27);
v16 = v30;
do
{
fprintf(stderr, "%02x", *(unsigned __int8 *)v16);
v16 = (__int64 *)((char *)v16 + 1);
}
while ( (__int64 *)((char *)v30 + v26) != v16 );
fputc(10, stderr);
if ( (unsigned __int16)v24 + 255 * (unsigned int)(unsigned __int8)v24 - 1 > 0xFFFF )
{
fwrite("This multiplier could overflow internal arithmetic.\n", 1uLL, 0x34uLL, stderr);
exit(1);
}
v17 = &argv[optind];
if ( v28 )
{
v18 = *v17;
v19 = 0x40000000LL;
if ( v18 )
v19 = strtoull(v18, 0LL, 0);
test_loop(v19, v15, v24, v26, v27, v30);
}
else
{
v20 = *v17;
v21 = -1LL;
if ( v20 )
v21 = strtoull(v20, 0LL, 0);
generate_loop(v21, v15);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    uint16_t a = 0;
    uint8_t r = 0;
    int quick = 0;
    tabptr_t const *table = ((void *)0);
    long tab_index = 0;
    uint8_t a_lo;
    int optc;
    while ((optc = getopt(argc, argv, "w:n:u:a:r:qh")) != -1)
        switch (optc)
        {
        case 'w':
            table = multiplier_table[WIDE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'n':
            table = multiplier_table[NARROW_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'u':
            table = multiplier_table[UNSAFE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'a':
            a = strtoul(optarg, ((void *)0), 0);
            break;
        case 'r':
            r = strtoul(optarg, ((void *)0), 0);
            break;
        case 'q': quick = 1;
            break;
        case 'h':
            usage();
            return 0;
        default:
            fprintf(stderr, "Invalid argument.\n");
            usage();
            exit(1);
        }
    if (r < 1 || r > 32)
    {
        fprintf(stderr, "Out-of-range lag value.\n");
        exit(1);
    }
    if (a == 0)
    {
        if (table == ((void *)0))
        {
            fprintf(stderr, "Must choose multiplier.\n");
            exit(1);
        }
        if (tab_index < 0)
            tab_index += table[r].len;
        if ((unsigned)tab_index >= table[r].len)
        {
            if (table[r].len > 0)
                fprintf(stderr, "Only %d known lag-%d multipliers.\n", table[r].len, r);
            else
                fprintf(stderr, "No known lag-%d multipliers.\n", r);
            exit(1);
        }
        a = table[r].tab[tab_index];
    }
    a_lo = a & 0xff;
    printf("b=256 a=0x%04x r=%d\n", a, r);
    if (255 * a_lo + a - 1 > 0xffff)
    {
        fprintf(stderr, "This multiplier could overflow internal arithmetic.\n");
        exit(1);
    }
    argc -= optind;
    argv += optind;
    test_loop(a, r, quick);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned short a = 0;
    unsigned char r = 0;
    int quick = 0;
    struct tabptr_t *table = ((void *)0);
    long tab_index = 0;
    unsigned char a_lo;
    int optc;
    while ((optc = getopt(argc, argv, "w:n:u:a:r:qh")) != -1)
        switch (optc)
        {
        case 'w':
            table = multiplier_table[WIDE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'n':
            table = multiplier_table[NARROW_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'u':
            table = multiplier_table[UNSAFE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'a':
            a = strtoul(optarg, ((void *)0), 0);
            break;
        case 'r':
            r = strtoul(optarg, ((void *)0), 0);
            break;
        case 'q': quick = 1;
            break;
        case 'h':
            usage();
            return 0;
        default:
            fprintf(stderr, "Invalid argument.\n");
            usage();
            exit(1);
        }
    if (r < 1 || r > 32)
    {
        fprintf(stderr, "Out-of-range lag value.\n");
        exit(1);
    }
    if (a == 0)
    {
        if (table == ((void *)0))
        {
            fprintf(stderr, "Must choose multiplier.\n");
            exit(1);
        }
        if (tab_index < 0)
            tab_index += table[r].len;
        if ((unsigned int)tab_index >= table[r].len)
        {
            if (table[r].len > 0)
                fprintf(stderr, "Only %d known lag-%d multipliers.\n", table[r].len, r);
            else
                fprintf(stderr, "No known lag-%d multipliers.\n", r);
            exit(1);
        }
        a = table[r].tab[tab_index];
    }
    a_lo = a & 0xff;
    printf("b=256 a=0x%04x r=%d\n", a, r);
    if (255 * a_lo + a - 1 > 0xffff)
    {
        fprintf(stderr, "This multiplier could overflow internal arithmetic.\n");
        exit(1);
    }
    argc -= optind;
    argv += optind;
    test_loop(a, r, quick);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
a
unsigned short

variable_types: quick int

variable_types: struct tabptr_t { int len; unsigned int *tab; } *

variable_types: optc int


hash

decompiled_code:
__int16 __fastcall hash(_BYTE *a1, unsigned __int8 a2, unsigned __int8 *a3, unsigned __int8 a4)
{
_BYTE *v4; // r11
unsigned __int8 v5; // r9
int v8; // edx
int v9; // eax
int v10; // eax
_BYTE *v11; // rcx
int v12; // ecx

v4 = &a1[a2];
v5 = a2 + a4;
if ( a2 + a4 )
{
v8 = 0;
v9 = 21845;
do
{
v12 = v9 + v8;
if ( (unsigned __int8)v8 < a4 )
v12 += *a3++;
if ( (unsigned __int8)v8 > a2 )
v12 += (unsigned __int8)*a1 << 8;
HIWORD(v10) = HIWORD(v12);
LOWORD(v10) = (unsigned __int16)v12 >> 11;
v9 = v12 ^ v10;
LOWORD(v9) = 233 * v9;
v11 = a1 + 1;
*a1 = BYTE1(v9);
a1 = &a1[-a2 + 1];
if ( v4 > v11 )
a1 = v11;
++v8;
}
while ( v5 > (unsigned __int8)v8 );
}
else
{
LOWORD(v9) = 21845;
}
return v9;
}

canonical_decompiled_code:
__int16 __fastcall func0(_BYTE *a1, unsigned __int8 a2, unsigned __int8 *a3, unsigned __int8 a4)
{
_BYTE *v4; // r11
unsigned __int8 v5; // r9
int v8; // edx
int v9; // eax
int v10; // eax
_BYTE *v11; // rcx
int v12; // ecx

v4 = &a1[a2];
v5 = a2 + a4;
if ( a2 + a4 )
{
v8 = 0;
v9 = 21845;
do
{
v12 = v9 + v8;
if ( (unsigned __int8)v8 < a4 )
v12 += *a3++;
if ( (unsigned __int8)v8 > a2 )
v12 += (unsigned __int8)*a1 << 8;
HIWORD(v10) = HIWORD(v12);
LOWORD(v10) = (unsigned __int16)v12 >> 11;
v9 = v12 ^ v10;
LOWORD(v9) = 233 * v9;
v11 = a1 + 1;
*a1 = BYTE1(v9);
a1 = &a1[-a2 + 1];
if ( v4 > v11 )
a1 = v11;
++v8;
}
while ( v5 > (unsigned __int8)v8 );
}
else
{
LOWORD(v9) = 21845;
}
return v9;
}

original_code:
static uint8_t hash(uint8_t *out, uint8_t olen, uint8_t const *in, uint8_t ilen)
{
    uint8_t i, l;
    uint8_t *end = out + olen;
    uint16_t seed = 0x5555;
    l = ilen + olen;
    for (i = 0; i < l; i++)
    {
        seed += i;
        if (i < ilen) seed += *in++;
        if (i > olen) seed += *out << 8;
        seed = (seed ^ (seed >> 11)) * 0xe9;
        *out++ = seed >> 8;
        if (out >= end)
            out -= olen;
    }
    return seed & 0xff;
}

canonical_original_code:
static unsigned char hash(unsigned char *out, unsigned char olen, unsigned char *in, unsigned char ilen)
{
    unsigned char i; unsigned char l;
    unsigned char *end = out + olen;
    unsigned short seed = 0x5555;
    l = ilen + olen;
    for (i = 0; i < l; i++)
    {
        seed += i;
        if (i < ilen) seed += *in++;
        if (i > olen) seed += *out << 8;
        seed = (seed ^ (seed >> 11)) * 0xe9;
        *out++ = seed >> 8;
        if (out >= end)
            out -= olen;
    }
    return seed & 0xff;
}

variable_types:
out
unsigned char *

variable_types:
olen
unsigned char

variable_types:
in
unsigned char *

variable_types:
ilen
unsigned char

variable_types:
i
unsigned char

variable_types:
l
unsigned char

variable_types:
end
unsigned char *

variable_types:
seed
unsigned short

return_type: unsigned char


decompiled_code:
__int16 __fastcall basicrand_seed(unsigned __int8 *a1, unsigned __int8 a2)
{
__int16 result; // ax

LOBYTE(result) = hash(&rand_state, 8u, a1, a2);
HIBYTE(result) = 85;
word_620 = result;
byte_622 = 0;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func1(unsigned __int8 *a1, unsigned __int8 a2)
{
__int16 result; // ax

LOBYTE(result) = func0(&rand_state, 8u, a1, a2);
HIBYTE(result) = 85;
word_620 = result;
byte_622 = 0;
return result;
}

original_code:
void basicrand_seed(void const *s, uint8_t l)
{
    rand_state.c = 0x5500 | hash(rand_state.x, sizeof(rand_state.x), s, l);
    rand_state.i = 0;
}

canonical_original_code:
void basicrand_seed(void *s, unsigned char l)
{
    rand_state.c = 0x5500 | hash(rand_state.x, sizeof(rand_state.x), s, l);
    rand_state.i = 0;
}

variable_types:
s
void *


basicrand

decompiled_code:
__int64 basicrand()
{
char v0; // di
int v1; // er9
int v2; // eax
int v3; // ecx
int v4; // edx
int v5; // esi
int v6; // eax
int v7; // eax

v0 = byte_622;
v1 = (unsigned __int8)byte_622 + 1;
v2 = (unsigned __int8)rand_state[(unsigned __int8)byte_622];
v3 = 23 * v2;
LOWORD(v3) = word_620 + 23 * v2;
HIWORD(v4) = HIWORD(v1);
v5 = (unsigned __int8)rand_state[v1];
LOWORD(v4) = 220 * v2;
v6 = v4 + 23 * v5;
HIWORD(v4) = HIWORD(v3);
LOWORD(v4) = BYTE1(v3);
v7 = v4 + v6;
rand_state[(unsigned __int8)byte_622] = v3;
rand_state[(unsigned __int8)v1] = v7;
word_620 = BYTE1(v7) + 220 * v5;
byte_622 = (v0 + 2) & 6;
return (unsigned __int8)v3 | (unsigned int)(v7 << 8);
}

canonical_decompiled_code:
__int64 func2()
{
char v0; // di
int v1; // er9
int v2; // eax
int v3; // ecx
int v4; // edx
int v5; // esi
int v6; // eax
int v7; // eax

v0 = byte_622;
v1 = (unsigned __int8)byte_622 + 1;
v2 = (unsigned __int8)rand_state[(unsigned __int8)byte_622];
v3 = 23 * v2;
LOWORD(v3) = word_620 + 23 * v2;
HIWORD(v4) = HIWORD(v1);
v5 = (unsigned __int8)rand_state[v1];
LOWORD(v4) = 220 * v2;
v6 = v4 + 23 * v5;
HIWORD(v4) = HIWORD(v3);
LOWORD(v4) = BYTE1(v3);
v7 = v4 + v6;
rand_state[(unsigned __int8)byte_622] = v3;
rand_state[(unsigned __int8)v1] = v7;
word_620 = BYTE1(v7) + 220 * v5;
byte_622 = (v0 + 2) & 6;
return (unsigned __int8)v3 | (unsigned int)(v7 << 8);
}

original_code:
uint16_t basicrand(void)
{
    uint8_t x, y;
    uint16_t c;
    uint8_t i;
    c = rand_state.c;
    i = rand_state.i;
    x = rand_state.x[i + 0];
    y = rand_state.x[i + 1];
    do { uint16_t t = ((uint16_t)((uint8_t)(0xdc17) * (uint8_t)(x))) + c; c = t >> 8; c += ((uint16_t)((uint8_t)((0xdc17 >> 8)) * (uint8_t)(x))); x = t & 0xff; } while (0);
    do { uint16_t t = ((uint16_t)((uint8_t)(0xdc17) * (uint8_t)(y))) + c; c = t >> 8; c += ((uint16_t)((uint8_t)((0xdc17 >> 8)) * (uint8_t)(y))); y = t & 0xff; } while (0);
    rand_state.x[i++] = x;
    rand_state.x[i++] = y;
    i &= 6;
    rand_state.c = c;
    rand_state.i = i;
    return (y << 8) | x;
}

canonical_original_code:
unsigned short basicrand()
{
    unsigned char x; unsigned char y;
    unsigned short c;
    unsigned char i;
    c = rand_state.c;
    i = rand_state.i;
    x = rand_state.x[i + 0];
    y = rand_state.x[i + 1];
    do { unsigned short t = ((uint16_t)((uint8_t)(0xdc17) * (uint8_t)(x))) + c; c = t >> 8; c += ((unsigned short)((unsigned char)((0xdc17 >> 8)) * (unsigned char)(x))); x = t & 0xff; } while (0);
    do { unsigned short t = ((uint16_t)((uint8_t)(0xdc17) * (uint8_t)(y))) + c; c = t >> 8; c += ((unsigned short)((unsigned char)((0xdc17 >> 8)) * (unsigned char)(y))); y = t & 0xff; } while (0);
    rand_state.x[i++] = x;
    rand_state.x[i++] = y;
    i &= 6;
    rand_state.c = c;
    rand_state.i = i;
    return (y << 8) | x;
}

variable_types:
x
unsigned char

variable_types:
y
unsigned char

variable_types:
c
unsigned short

variable_types:
t
unsigned short

return_type: unsigned short


decompiled_code:
__int16 __fastcall newrand_seed(unsigned __int8 *a1, unsigned __int8 a2)
{
__int16 result; // ax

LOBYTE(result) = hash(&byte_60F, 3u, a1, a2);
HIBYTE(result) = 85;
newrand_state = result;
byte_60E = 0;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func3(unsigned __int8 *a1, unsigned __int8 a2)
{
__int16 result; // ax

LOBYTE(result) = func0(&byte_60F, 3u, a1, a2);
HIBYTE(result) = 85;
newrand_state = result;
byte_60E = 0;
return result;
}

original_code:
void newrand_seed(void const *s, uint8_t l)
{
    newrand_state.c0 = 0x5500 | hash(newrand_state.x, sizeof(newrand_state.x), s, l);
    newrand_state.c1 = 0;
}

canonical_original_code:
void newrand_seed(void *s, unsigned char l)
{
    newrand_state.c0 = 0x5500 | hash(newrand_state.x, sizeof(newrand_state.x), s, l);
    newrand_state.c1 = 0;
}


newrand

decompiled_code:
__int64 newrand()
{
unsigned __int8 v0; // al
unsigned int v1; // edx

v0 = -56 * byte_60F + newrand_state;
v1 = ((unsigned int)(((16580608 * (unsigned __int8)byte_60F) | (unsigned __int16)(200 * (unsigned __int8)byte_60F))
+ ((unsigned __int16)newrand_state | ((unsigned __int8)byte_60E << 16))) >> 8)
+ ((unsigned __int16)(200 * (unsigned __int8)byte_610) | (16580608 * (unsigned __int8)byte_610));
newrand_state = v1 >> 8;
byte_60E = HIBYTE(v1);
byte_60F = byte_611;
byte_610 = v0;
byte_611 = v1;
return (v1 << 8) | v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned __int8 v0; // al
unsigned int v1; // edx

v0 = -56 * byte_60F + newrand_state;
v1 = ((unsigned int)(((16580608 * (unsigned __int8)byte_60F) | (unsigned __int16)(200 * (unsigned __int8)byte_60F))
+ ((unsigned __int16)newrand_state | ((unsigned __int8)byte_60E << 16))) >> 8)
+ ((unsigned __int16)(200 * (unsigned __int8)byte_610) | (16580608 * (unsigned __int8)byte_610));
newrand_state = v1 >> 8;
byte_60E = HIBYTE(v1);
byte_60F = byte_611;
byte_610 = v0;
byte_611 = v1;
return (v1 << 8) | v0;
}

original_code:
uint16_t newrand(void)
{
    uint8_t x, y, z;
    uint32_t c;
    c = newrand_state.c0 | ((uint32_t)newrand_state.c1 << 16);
    x = newrand_state.x[0];
    y = newrand_state.x[1];
    z = newrand_state.x[2];
    do { uint32_t t = ((uint16_t)((uint8_t)(0xfd00c8ul) * (uint8_t)(x))); t |= (uint32_t)((uint16_t)((uint8_t)((0xfd00c8ul >> 16)) * (uint8_t)(x))) << 16; t += c; c = t >> 8; x = t & 0xff; } while (0);
    do { uint32_t t = ((uint16_t)((uint8_t)(0xfd00c8ul) * (uint8_t)(y))); t |= (uint32_t)((uint16_t)((uint8_t)((0xfd00c8ul >> 16)) * (uint8_t)(y))) << 16; t += c; c = t >> 8; y = t & 0xff; } while (0);
    newrand_state.c0 = (uint16_t)c;
    newrand_state.c1 = (uint8_t)(c >> 16);
    newrand_state.x[0] = z;
    newrand_state.x[1] = x;
    newrand_state.x[2] = y;
    return (y << 8) | x;
}

canonical_original_code:
unsigned short newrand()
{
    unsigned char x; unsigned char y; unsigned char z;
    unsigned int c;
    c = newrand_state.c0 | ((unsigned int)newrand_state.c1 << 16);
    x = newrand_state.x[0];
    y = newrand_state.x[1];
    z = newrand_state.x[2];
    do { unsigned int t = ((uint16_t)((uint8_t)(0xfd00c8ul) * (uint8_t)(x))); t |= (unsigned int)((unsigned short)((unsigned char)((0xfd00c8ul >> 16)) * (unsigned char)(x))) << 16; t += c; c = t >> 8; x = t & 0xff; } while (0);
    do { unsigned int t = ((uint16_t)((uint8_t)(0xfd00c8ul) * (uint8_t)(y))); t |= (unsigned int)((unsigned short)((unsigned char)((0xfd00c8ul >> 16)) * (unsigned char)(y))) << 16; t += c; c = t >> 8; y = t & 0xff; } while (0);
    newrand_state.c0 = (unsigned short)c;
    newrand_state.c1 = (unsigned char)(c >> 16);
    newrand_state.x[0] = z;
    newrand_state.x[1] = x;
    newrand_state.x[2] = y;
    return (y << 8) | x;
}

variable_types:
z
unsigned char

variable_types:
c
unsigned int

variable_types:
t
unsigned int


decompiled_code:
__int16 __fastcall tinyrand_seed(unsigned __int8 *a1, unsigned __int8 a2)
{
__int16 result; // ax

LOBYTE(result) = hash(&tinyrand_state, 2u, a1, a2);
HIBYTE(result) = 85;
word_60A = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func5(unsigned __int8 *a1, unsigned __int8 a2)
{
__int16 result; // ax

LOBYTE(result) = func0(&tinyrand_state, 2u, a1, a2);
HIBYTE(result) = 85;
word_60A = result;
return result;
}

original_code:
void tinyrand_seed(void const *s, uint8_t l)
{
    tinyrand_state.c = 0x5500 | hash(tinyrand_state.x, sizeof(tinyrand_state.x), s, l);
}

canonical_original_code:
void tinyrand_seed(void *s, unsigned char l)
{
    tinyrand_state.c = 0x5500 | hash(tinyrand_state.x, sizeof(tinyrand_state.x), s, l);
}


tinyrand

decompiled_code:
__int64 __fastcall tinyrand(__int64 a1, __int64 a2, int a3)
{
unsigned __int16 v3; // cx
int v4; // eax
int v5; // edx
int v6; // eax

v3 = word_60A + 7 * (unsigned __int8)tinyrand_state;
LOWORD(a3) = 206 * (unsigned __int8)tinyrand_state;
v4 = a3 + 7 * (unsigned __int8)byte_609;
HIWORD(v5) = (7 * (unsigned int)(unsigned __int8)tinyrand_state) >> 16;
LOWORD(v5) = HIBYTE(v3);
v6 = v5 + v4;
word_60A = BYTE1(v6) + 206 * (unsigned __int8)byte_609;
tinyrand_state = v3;
byte_609 = v6;
return (unsigned __int8)v3 | (unsigned int)(v6 << 8);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, int a3)
{
unsigned __int16 v3; // cx
int v4; // eax
int v5; // edx
int v6; // eax

v3 = word_60A + 7 * (unsigned __int8)tinyrand_state;
LOWORD(a3) = 206 * (unsigned __int8)tinyrand_state;
v4 = a3 + 7 * (unsigned __int8)byte_609;
HIWORD(v5) = (7 * (unsigned int)(unsigned __int8)tinyrand_state) >> 16;
LOWORD(v5) = HIBYTE(v3);
v6 = v5 + v4;
word_60A = BYTE1(v6) + 206 * (unsigned __int8)byte_609;
tinyrand_state = v3;
byte_609 = v6;
return (unsigned __int8)v3 | (unsigned int)(v6 << 8);
}

original_code:
uint16_t tinyrand(void)
{
    uint8_t x, y;
    uint16_t c;
    c = tinyrand_state.c;
    x = tinyrand_state.x[0];
    y = tinyrand_state.x[1];
    do { uint16_t t = ((uint16_t)((uint8_t)(0xce07) * (uint8_t)(x))) + c; c = t >> 8; c += ((uint16_t)((uint8_t)((0xce07 >> 8)) * (uint8_t)(x))); x = t & 0xff; } while (0);
    do { uint16_t t = ((uint16_t)((uint8_t)(0xce07) * (uint8_t)(y))) + c; c = t >> 8; c += ((uint16_t)((uint8_t)((0xce07 >> 8)) * (uint8_t)(y))); y = t & 0xff; } while (0);
    tinyrand_state.c = c;
    tinyrand_state.x[0] = x;
    tinyrand_state.x[1] = y;
    return (y << 8) | x;
}

canonical_original_code:
unsigned short tinyrand()
{
    unsigned char x; unsigned char y;
    unsigned short c;
    c = tinyrand_state.c;
    x = tinyrand_state.x[0];
    y = tinyrand_state.x[1];
    do { unsigned short t = ((uint16_t)((uint8_t)(0xce07) * (uint8_t)(x))) + c; c = t >> 8; c += ((unsigned short)((unsigned char)((0xce07 >> 8)) * (unsigned char)(x))); x = t & 0xff; } while (0);
    do { unsigned short t = ((uint16_t)((uint8_t)(0xce07) * (uint8_t)(y))) + c; c = t >> 8; c += ((unsigned short)((unsigned char)((0xce07 >> 8)) * (unsigned char)(y))); y = t & 0xff; } while (0);
    tinyrand_state.c = c;
    tinyrand_state.x[0] = x;
    tinyrand_state.x[1] = y;
    return (y << 8) | x;
}


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

result = (unsigned __int8)hash(fastrand_state, 6u, a1, a2) | 0x80u;
word_606 = (unsigned __int8)result;
return result;
}

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

result = (unsigned __int8)func0(fastrand_state, 6u, a1, a2) | 0x80u;
word_606 = (unsigned __int8)result;
return result;
}

original_code:
void fastrand_seed(void const *s, uint8_t l)
{
    fastrand_state.c = 0x0080 | hash(fastrand_state.x, sizeof(fastrand_state.x), s, l);
}

canonical_original_code:
void fastrand_seed(void *s, unsigned char l)
{
    fastrand_state.c = 0x0080 | hash(fastrand_state.x, sizeof(fastrand_state.x), s, l);
}


fastrand

decompiled_code:
__int64 fastrand()
{
int v0; // edx
__int16 v1; // r9
__int64 v2; // rsi
int v3; // edi
int v4; // edx
__int64 v5; // r8
int v6; // ecx
int v7; // eax
int v8; // eax
__int16 v9; // di
__int16 v10; // cx

v0 = (unsigned __int16)word_606;
v1 = HIBYTE(word_606) & 6;
v2 = HIBYTE(word_606) & 6;
v3 = (unsigned __int8)fastrand_state[v2];
LOWORD(v0) = word_606 & 0x1FF;
v4 = 59 * v3 + v0;
v5 = ((_BYTE)v1 + 1) & 0xF;
v6 = (unsigned __int8)fastrand_state[v5];
v7 = v3 + 59 * v6;
HIWORD(v3) = HIWORD(v4);
LOWORD(v3) = BYTE1(v4);
v8 = v3 + v7;
v9 = v6 + BYTE1(v8);
fastrand_state[v2] = v4;
v10 = v1 + 2;
fastrand_state[v5] = v8;
if ( (_BYTE)v1 == 4 )
v10 = 0;
word_606 = v9 | (v10 << 8);
return (unsigned __int8)v4 | (unsigned int)(v8 << 8);
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // edx
__int16 v1; // r9
__int64 v2; // rsi
int v3; // edi
int v4; // edx
__int64 v5; // r8
int v6; // ecx
int v7; // eax
int v8; // eax
__int16 v9; // di
__int16 v10; // cx

v0 = (unsigned __int16)word_606;
v1 = HIBYTE(word_606) & 6;
v2 = HIBYTE(word_606) & 6;
v3 = (unsigned __int8)fastrand_state[v2];
LOWORD(v0) = word_606 & 0x1FF;
v4 = 59 * v3 + v0;
v5 = ((_BYTE)v1 + 1) & 0xF;
v6 = (unsigned __int8)fastrand_state[v5];
v7 = v3 + 59 * v6;
HIWORD(v3) = HIWORD(v4);
LOWORD(v3) = BYTE1(v4);
v8 = v3 + v7;
v9 = v6 + BYTE1(v8);
fastrand_state[v2] = v4;
v10 = v1 + 2;
fastrand_state[v5] = v8;
if ( (_BYTE)v1 == 4 )
v10 = 0;
word_606 = v9 | (v10 << 8);
return (unsigned __int8)v4 | (unsigned int)(v8 << 8);
}

original_code:
uint16_t fastrand(void)
{
    uint8_t x, y;
    uint16_t c;
    uint8_t i;
    c = fastrand_state.c;
    i = (c >> 8) & 6;
    c &= 0x1ff;
    x = fastrand_state.x[i + 0];
    y = fastrand_state.x[i + 1];
    do { uint16_t t = ((uint16_t)((uint8_t)(0x013b) * (uint8_t)(x))) + c; c = t >> 8; if (0x013b & 0x100) c += x; x = t & 0xff; } while (0);
    do { uint16_t t = ((uint16_t)((uint8_t)(0x013b) * (uint8_t)(y))) + c; c = t >> 8; if (0x013b & 0x100) c += y; y = t & 0xff; } while (0);
    fastrand_state.x[i++] = x;
    fastrand_state.x[i++] = y;
    if (i == sizeof(fastrand_state.x))
        i = 0;
    fastrand_state.c = c | ((uint16_t)i << 8);
    return (y << 8) | x;
}

canonical_original_code:
unsigned short fastrand()
{
    unsigned char x; unsigned char y;
    unsigned short c;
    unsigned char i;
    c = fastrand_state.c;
    i = (c >> 8) & 6;
    c &= 0x1ff;
    x = fastrand_state.x[i + 0];
    y = fastrand_state.x[i + 1];
    do { unsigned short t = ((uint16_t)((uint8_t)(0x013b) * (uint8_t)(x))) + c; c = t >> 8; if (0x013b & 0x100) c += x; x = t & 0xff; } while (0);
    do { unsigned short t = ((uint16_t)((uint8_t)(0x013b) * (uint8_t)(y))) + c; c = t >> 8; if (0x013b & 0x100) c += y; y = t & 0xff; } while (0);
    fastrand_state.x[i++] = x;
    fastrand_state.x[i++] = y;
    if (i == sizeof(fastrand_state.x))
        i = 0;
    fastrand_state.c = c | ((unsigned short)i << 8);
    return (y << 8) | x;
}


decompiled_code:
__int64 __fastcall shiftrand_seed(unsigned __int8 *a1, unsigned __int8 a2)
{
return fastrand_seed(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 *a1, unsigned __int8 a2)
{
return func7(a1, a2);
}

original_code:
void shiftrand_seed(void const *s, uint8_t l)
{
    fastrand_seed(s, l);
}

canonical_original_code:
void shiftrand_seed(void *s, unsigned char l)
{
    fastrand_seed(s, l);
}


shiftrand

decompiled_code:
__int64 shiftrand()
{
int v0; // eax
__int16 v1; // r9
__int64 v2; // rsi
int v3; // er8
unsigned __int8 v4; // dl
int v5; // er10
__int64 v6; // rdi
int v7; // ecx
int v8; // eax
__int16 v9; // r8
__int16 v10; // cx

v0 = (unsigned __int16)word_606;
v1 = HIBYTE(word_606) & 6;
v2 = HIBYTE(word_606) & 6;
v3 = (unsigned __int8)fastrand_state[v2];
LOWORD(v0) = word_606 & 0x1FF;
v4 = 63 * fastrand_state[v2] + word_606 - 4 * v3;
v5 = 63 * v3 + v0 - 4 * v3;
LOWORD(v5) = (unsigned __int16)(63 * (unsigned __int8)fastrand_state[v2] + (word_606 & 0x1FF) - 4 * v3) >> 8;
v6 = ((_BYTE)v1 + 1) & 0xF;
v7 = (unsigned __int8)fastrand_state[v6];
v8 = v5 + v3 + 63 * v7 - 4 * v7;
v9 = v7 + BYTE1(v8);
fastrand_state[v2] = v4;
v10 = v1 + 2;
fastrand_state[v6] = v8;
if ( (_BYTE)v1 == 4 )
v10 = 0;
word_606 = v9 | (v10 << 8);
return v4 | (unsigned int)(v8 << 8);
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // eax
__int16 v1; // r9
__int64 v2; // rsi
int v3; // er8
unsigned __int8 v4; // dl
int v5; // er10
__int64 v6; // rdi
int v7; // ecx
int v8; // eax
__int16 v9; // r8
__int16 v10; // cx

v0 = (unsigned __int16)word_606;
v1 = HIBYTE(word_606) & 6;
v2 = HIBYTE(word_606) & 6;
v3 = (unsigned __int8)fastrand_state[v2];
LOWORD(v0) = word_606 & 0x1FF;
v4 = 63 * fastrand_state[v2] + word_606 - 4 * v3;
v5 = 63 * v3 + v0 - 4 * v3;
LOWORD(v5) = (unsigned __int16)(63 * (unsigned __int8)fastrand_state[v2] + (word_606 & 0x1FF) - 4 * v3) >> 8;
v6 = ((_BYTE)v1 + 1) & 0xF;
v7 = (unsigned __int8)fastrand_state[v6];
v8 = v5 + v3 + 63 * v7 - 4 * v7;
v9 = v7 + BYTE1(v8);
fastrand_state[v2] = v4;
v10 = v1 + 2;
fastrand_state[v6] = v8;
if ( (_BYTE)v1 == 4 )
v10 = 0;
word_606 = v9 | (v10 << 8);
return v4 | (unsigned int)(v8 << 8);
}

original_code:
uint16_t shiftrand(void)
{
    uint8_t x, y, i;
    uint16_t c, t;
    c = fastrand_state.c;
    i = (c >> 8) & 6;
    c &= 0x1ff;
    x = fastrand_state.x[i + 0];
    y = fastrand_state.x[i + 1];
    t = (x << 6) - x - (x << 2) + c;
    c = (t >> 8) + x;
    x = t & 0xff;
    t = (y << 6) - y - (y << 2) + c;
    c = (t >> 8) + y;
    y = t & 0xff;
    fastrand_state.x[i++] = x;
    fastrand_state.x[i++] = y;
    if (i == sizeof(fastrand_state.x))
        i = 0;
    fastrand_state.c = c | ((uint16_t)i << 8);
    return (y << 8) | x;
}

canonical_original_code:
unsigned short shiftrand()
{
    unsigned char x; unsigned char y; unsigned char i;
    unsigned short c; unsigned short t;
    c = fastrand_state.c;
    i = (c >> 8) & 6;
    c &= 0x1ff;
    x = fastrand_state.x[i + 0];
    y = fastrand_state.x[i + 1];
    t = (x << 6) - x - (x << 2) + c;
    c = (t >> 8) + x;
    x = t & 0xff;
    t = (y << 6) - y - (y << 2) + c;
    c = (t >> 8) + y;
    y = t & 0xff;
    fastrand_state.x[i++] = x;
    fastrand_state.x[i++] = y;
    if (i == sizeof(fastrand_state.x))
        i = 0;
    fastrand_state.c = c | ((unsigned short)i << 8);
    return (y << 8) | x;
}


decompiled_code:
__int16 __fastcall fastrand2_seed(unsigned __int8 *a1, unsigned __int8 a2)
{
__int16 result; // ax

result = hash(&fastrand2_state, 8u, a1, a2);
byte_5F8 = result;
byte_5F9 = 85;
byte_5FA = 0;
byte_5FB = 0;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func11(unsigned __int8 *a1, unsigned __int8 a2)
{
__int16 result; // ax

result = func0(&fastrand2_state, 8u, a1, a2);
byte_5F8 = result;
byte_5F9 = 85;
byte_5FA = 0;
byte_5FB = 0;
return result;
}

original_code:
void fastrand2_seed(void const *s, uint8_t l)
{
    fastrand2_state.c[0] = hash(fastrand2_state.x, sizeof(fastrand2_state.x), s, l);
    fastrand2_state.c[1] = 0x55;
    fastrand2_state.c[2] = 0;
    fastrand2_state.c[3] = 0;
}

canonical_original_code:
void fastrand2_seed(void *s, unsigned char l)
{
    fastrand2_state.c[0] = hash(fastrand2_state.x, sizeof(fastrand2_state.x), s, l);
    fastrand2_state.c[1] = 0x55;
    fastrand2_state.c[2] = 0;
    fastrand2_state.c[3] = 0;
}


decompiled_code:
__int64 fastrand2()
{
char v0; // r8
__int64 v1; // r11
unsigned __int8 v2; // al
__int64 v3; // r10
__int16 v4; // bx
int v5; // edi
unsigned __int8 v6; // r9
int v7; // edi
unsigned __int8 v8; // si
unsigned __int16 v9; // ax
unsigned __int16 v10; // dx
__int16 v11; // ax
unsigned __int16 v12; // cx
unsigned __int16 v13; // cx
unsigned __int16 v14; // cx
__int16 v15; // ax

v0 = (unsigned __int8)byte_5FB >> 1;
v1 = (unsigned __int8)byte_5FB >> 1;
v2 = fastrand2_state[v1];
v3 = (unsigned __int8)(((unsigned __int8)byte_5FB >> 1) + 1);
v4 = v2;
v5 = v2 + (unsigned __int8)byte_5F8;
v6 = v2 + byte_5F8;
LOWORD(v5) = BYTE1(v5);
v7 = (unsigned __int8)byte_5F9 + v5;
v9 = BYTE1(v7) + 13 * v2 + (unsigned __int8)byte_5FA;
v8 = v9;
v10 = HIBYTE(v9) + v4 + (byte_5FB & 1);
v11 = (unsigned __int8)fastrand2_state[v3];
v12 = v11 + (unsigned __int8)v7;
LOBYTE(v7) = fastrand2_state[v3] + v7;
v13 = v8 + HIBYTE(v12);
byte_5F8 = v13;
v14 = 13 * v11 + (unsigned __int8)v10 + HIBYTE(v13);
byte_5F9 = v14;
v15 = HIBYTE(v14) + HIBYTE(v10) + v11;
byte_5FA = v15;
fastrand2_state[v1] = v6;
fastrand2_state[v3] = v7;
byte_5FB = (2 * v0 + 4) & 0xE | HIBYTE(v15);
return (v7 << 8) | (unsigned int)v6;
}

canonical_decompiled_code:
__int64 func12()
{
char v0; // r8
__int64 v1; // r11
unsigned __int8 v2; // al
__int64 v3; // r10
__int16 v4; // bx
int v5; // edi
unsigned __int8 v6; // r9
int v7; // edi
unsigned __int8 v8; // si
unsigned __int16 v9; // ax
unsigned __int16 v10; // dx
__int16 v11; // ax
unsigned __int16 v12; // cx
unsigned __int16 v13; // cx
unsigned __int16 v14; // cx
__int16 v15; // ax

v0 = (unsigned __int8)byte_5FB >> 1;
v1 = (unsigned __int8)byte_5FB >> 1;
v2 = fastrand2_state[v1];
v3 = (unsigned __int8)(((unsigned __int8)byte_5FB >> 1) + 1);
v4 = v2;
v5 = v2 + (unsigned __int8)byte_5F8;
v6 = v2 + byte_5F8;
LOWORD(v5) = BYTE1(v5);
v7 = (unsigned __int8)byte_5F9 + v5;
v9 = BYTE1(v7) + 13 * v2 + (unsigned __int8)byte_5FA;
v8 = v9;
v10 = HIBYTE(v9) + v4 + (byte_5FB & 1);
v11 = (unsigned __int8)fastrand2_state[v3];
v12 = v11 + (unsigned __int8)v7;
LOBYTE(v7) = fastrand2_state[v3] + v7;
v13 = v8 + HIBYTE(v12);
byte_5F8 = v13;
v14 = 13 * v11 + (unsigned __int8)v10 + HIBYTE(v13);
byte_5F9 = v14;
v15 = HIBYTE(v14) + HIBYTE(v10) + v11;
byte_5FA = v15;
fastrand2_state[v1] = v6;
fastrand2_state[v3] = v7;
byte_5FB = (2 * v0 + 4) & 0xE | HIBYTE(v15);
return (v7 << 8) | (unsigned int)v6;
}

original_code:
uint16_t fastrand2(void)
{
    uint8_t x, y;
    uint8_t i;
    i = (fastrand2_state.c[3] >> 1);
    x = fastrand2_state.x[i + 0];
    y = fastrand2_state.x[i + 1];
    do { uint16_t t = x + fastrand2_state.c[0]; uint8_t out = t & 255; t >>= 8; t += fastrand2_state.c[1]; fastrand2_state.c[0] = t & 255; t >>= 8; t += fastrand2_state.c[2]; t += ((uint16_t)((uint8_t)(0x010D0001 >> 16) * (uint8_t)(x))); fastrand2_state.c[1] = t & 255; t >>= 8; t += fastrand2_state.c[3] & 1; t += x; fastrand2_state.c[2] = t & 255; t >>= 8; fastrand2_state.c[3] = t & 1; x = out; } while (0);
    do { uint16_t t = y + fastrand2_state.c[0]; uint8_t out = t & 255; t >>= 8; t += fastrand2_state.c[1]; fastrand2_state.c[0] = t & 255; t >>= 8; t += fastrand2_state.c[2]; t += ((uint16_t)((uint8_t)(0x010D0001 >> 16) * (uint8_t)(y))); fastrand2_state.c[1] = t & 255; t >>= 8; t += fastrand2_state.c[3] & 1; t += y; fastrand2_state.c[2] = t & 255; t >>= 8; fastrand2_state.c[3] = t & 1; y = out; } while (0);
    fastrand2_state.x[i++] = x;
    fastrand2_state.x[i++] = y;
    fastrand2_state.c[3] |= (i & 7) << 1;
    return (y << 8) | x;
}

canonical_original_code:
unsigned short fastrand2()
{
    unsigned char x; unsigned char y;
    unsigned char i;
    i = (fastrand2_state.c[3] >> 1);
    x = fastrand2_state.x[i + 0];
    y = fastrand2_state.x[i + 1];
    do { unsigned short t = x + fastrand2_state.c[0]; unsigned char out = t & 255; t >>= 8; t += fastrand2_state.c[1]; fastrand2_state.c[0] = t & 255; t >>= 8; t += fastrand2_state.c[2]; t += ((unsigned short)((unsigned char)(0x010D0001 >> 16) * (unsigned char)(x))); fastrand2_state.c[1] = t & 255; t >>= 8; t += fastrand2_state.c[3] & 1; t += x; fastrand2_state.c[2] = t & 255; t >>= 8; fastrand2_state.c[3] = t & 1; x = out; } while (0);
    do { unsigned short t = y + fastrand2_state.c[0]; unsigned char out = t & 255; t >>= 8; t += fastrand2_state.c[1]; fastrand2_state.c[0] = t & 255; t >>= 8; t += fastrand2_state.c[2]; t += ((unsigned short)((unsigned char)(0x010D0001 >> 16) * (unsigned char)(y))); fastrand2_state.c[1] = t & 255; t >>= 8; t += fastrand2_state.c[3] & 1; t += y; fastrand2_state.c[2] = t & 255; t >>= 8; fastrand2_state.c[3] = t & 1; y = out; } while (0);
    fastrand2_state.x[i++] = x;
    fastrand2_state.x[i++] = y;
    fastrand2_state.c[3] |= (i & 7) << 1;
    return (y << 8) | x;
}

variable_types:
out
unsigned char


decompiled_code:
__int64 __fastcall rand8_init(unsigned int a1, unsigned __int8 a2, __int16 a3, __int64 a4)
{
__int64 result; // rax

result = a1;
word_2A5 = a1;
byte_2A4 = a2;
if ( a2 )
{
result = 0LL;
do
{
rand8[result] = *(_BYTE *)(a4 + result);
++result;
}
while ( a2 > (int)result );
}
word_2A0 = a3;
byte_2A2 = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned __int8 a2, __int16 a3, __int64 a4)
{
__int64 result; // rax

result = a1;
word_2A5 = a1;
byte_2A4 = a2;
if ( a2 )
{
result = 0LL;
do
{
rand8[result] = *(_BYTE *)(a4 + result);
++result;
}
while ( a2 > (int)result );
}
word_2A0 = a3;
byte_2A2 = 0;
return result;
}

original_code:
void rand8_init(uint16_t a, uint8_t r, uint16_t c, uint8_t const *seed)
{
    int i;
    rand8.mul_lo = a & 0xff;
    rand8.mul_hi = a >> 8;
    rand8.r = r;
    for (i = 0; i < r; i++)
        rand8.state[i] = seed[i];
    rand8.c = c;
    rand8.i = 0;
}

canonical_original_code:
void rand8_init(unsigned short a, unsigned char r, unsigned short c, unsigned char *seed)
{
    int i;
    rand8.mul_lo = a & 0xff;
    rand8.mul_hi = a >> 8;
    rand8.r = r;
    for (i = 0; i < r; i++)
        rand8.state[i] = seed[i];
    rand8.c = c;
    rand8.i = 0;
}

variable_types:
a
unsigned short

variable_types:
r
unsigned char

variable_types:
seed
unsigned char *

variable_types: i int


decompiled_code:
unsigned __int16 rand8_8bit()
{
char v0; // dl
unsigned __int16 result; // ax
unsigned __int8 v2; // dl

v0 = byte_2A2;
result = word_2A0 + (unsigned __int8)word_2A5 * (unsigned __int8)rand8[(unsigned __int8)byte_2A2];
rand8[(unsigned __int8)byte_2A2] = result;
word_2A0 = HIBYTE(result);
v2 = v0 + 1;
if ( (unsigned __int8)byte_2A4 <= v2 )
v2 = 0;
byte_2A2 = v2;
return result;
}

canonical_decompiled_code:
unsigned __int16 func1()
{
char v0; // dl
unsigned __int16 result; // ax
unsigned __int8 v2; // dl

v0 = byte_2A2;
result = word_2A0 + (unsigned __int8)word_2A5 * (unsigned __int8)rand8[(unsigned __int8)byte_2A2];
rand8[(unsigned __int8)byte_2A2] = result;
word_2A0 = HIBYTE(result);
v2 = v0 + 1;
if ( (unsigned __int8)byte_2A4 <= v2 )
v2 = 0;
byte_2A2 = v2;
return result;
}

original_code:
uint8_t rand8_8bit(void)
{
    uint8_t i = rand8.i;
    uint8_t x = rand8.state[i];
    uint16_t c = rand8.c;
    uint16_t t;
    t = (uint16_t)((uint8_t)(x) * (uint8_t)(rand8.mul_lo)) + c;
    c = t >> 8;
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}

canonical_original_code:
unsigned char rand8_8bit()
{
    unsigned char i = rand8.i;
    unsigned char x = rand8.state[i];
    unsigned short c = rand8.c;
    unsigned short t;
    t = (unsigned short)((unsigned char)(x) * (unsigned char)(rand8.mul_lo)) + c;
    c = t >> 8;
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}

variable_types:
i
unsigned char


decompiled_code:
__int64 rand16_8bit()
{
unsigned __int8 v0; // bl
int v1; // eax

v0 = rand8_8bit();
LOWORD(v1) = rand8_8bit();
return (unsigned int)v0 + (v1 << 8);
}

canonical_decompiled_code:
__int64 func2()
{
unsigned __int8 v0; // bl
int v1; // eax

v0 = func1();
LOWORD(v1) = func1();
return (unsigned int)v0 + (v1 << 8);
}

original_code:
uint16_t rand16_8bit(void)
{
    uint8_t x, y;
    x = rand8_8bit();
    y = rand8_8bit();
    return ((uint16_t)y << 8) + x;
}

canonical_original_code:
unsigned short rand16_8bit()
{
    unsigned char x; unsigned char y;
    x = rand8_8bit();
    y = rand8_8bit();
    return ((unsigned short)y << 8) + x;
}


decompiled_code:
__int64 rand32_8bit()
{
unsigned __int16 v0; // bx

v0 = rand16_8bit();
return v0 + ((unsigned int)rand16_8bit() << 16);
}

canonical_decompiled_code:
__int64 func3()
{
unsigned __int16 v0; // bx

v0 = func2();
return v0 + ((unsigned int)func2() << 16);
}

original_code:
uint32_t rand32_8bit(void)
{
    uint16_t x, y;
    x = rand16_8bit();
    y = rand16_8bit();
    return ((uint32_t)y << 16) + x;
}

canonical_original_code:
unsigned int rand32_8bit()
{
    unsigned short x; unsigned short y;
    x = rand16_8bit();
    y = rand16_8bit();
    return ((unsigned int)y << 16) + x;
}

variable_types:
x
unsigned short

variable_types:
y
unsigned short

return_type: unsigned int


decompiled_code:
unsigned __int16 rand8_9bit()
{
int v0; // edx
__int16 v1; // cx
unsigned __int16 result; // ax
int v3; // edx

v0 = (unsigned __int8)byte_2A2;
v1 = (unsigned __int8)rand8[(unsigned __int8)byte_2A2];
result = word_2A0 + v1 * (unsigned __int8)word_2A5;
rand8[(unsigned __int8)byte_2A2] = result;
word_2A0 = HIBYTE(result) + v1;
v3 = v0 + 1;
if ( (unsigned __int8)byte_2A4 <= v3 )
LOBYTE(v3) = 0;
byte_2A2 = v3;
return result;
}

canonical_decompiled_code:
unsigned __int16 func4()
{
int v0; // edx
__int16 v1; // cx
unsigned __int16 result; // ax
int v3; // edx

v0 = (unsigned __int8)byte_2A2;
v1 = (unsigned __int8)rand8[(unsigned __int8)byte_2A2];
result = word_2A0 + v1 * (unsigned __int8)word_2A5;
rand8[(unsigned __int8)byte_2A2] = result;
word_2A0 = HIBYTE(result) + v1;
v3 = v0 + 1;
if ( (unsigned __int8)byte_2A4 <= v3 )
LOBYTE(v3) = 0;
byte_2A2 = v3;
return result;
}

original_code:
uint8_t rand8_9bit(void)
{
    int i = rand8.i;
    uint8_t x = rand8.state[i];
    uint16_t c = rand8.c;
    uint16_t t;
    t = (uint16_t)((uint8_t)(x) * (uint8_t)(rand8.mul_lo)) + c;
    c = t >> 8;
    c += x;
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}

canonical_original_code:
unsigned char rand8_9bit()
{
    int i = rand8.i;
    unsigned char x = rand8.state[i];
    unsigned short c = rand8.c;
    unsigned short t;
    t = (unsigned short)((unsigned char)(x) * (unsigned char)(rand8.mul_lo)) + c;
    c = t >> 8;
    c += x;
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}


decompiled_code:
__int64 rand16_9bit()
{
unsigned __int8 v0; // bl
int v1; // eax

v0 = rand8_9bit();
LOWORD(v1) = rand8_9bit();
return (unsigned int)v0 + (v1 << 8);
}

canonical_decompiled_code:
__int64 func5()
{
unsigned __int8 v0; // bl
int v1; // eax

v0 = func4();
LOWORD(v1) = func4();
return (unsigned int)v0 + (v1 << 8);
}

original_code:
uint16_t rand16_9bit(void)
{
    uint8_t x, y;
    x = rand8_9bit();
    y = rand8_9bit();
    return ((uint16_t)y << 8) + x;
}

canonical_original_code:
unsigned short rand16_9bit()
{
    unsigned char x; unsigned char y;
    x = rand8_9bit();
    y = rand8_9bit();
    return ((unsigned short)y << 8) + x;
}


decompiled_code:
__int64 rand32_9bit()
{
unsigned __int16 v0; // bx

v0 = rand16_9bit();
return v0 + ((unsigned int)rand16_9bit() << 16);
}

canonical_decompiled_code:
__int64 func6()
{
unsigned __int16 v0; // bx

v0 = func5();
return v0 + ((unsigned int)func5() << 16);
}

original_code:
uint32_t rand32_9bit(void)
{
    uint16_t x, y;
    x = rand16_9bit();
    y = rand16_9bit();
    return ((uint32_t)y << 16) + x;
}

canonical_original_code:
unsigned int rand32_9bit()
{
    unsigned short x; unsigned short y;
    x = rand16_9bit();
    y = rand16_9bit();
    return ((unsigned int)y << 16) + x;
}


decompiled_code:
unsigned __int16 rand8_16bit()
{
int v0; // edx
__int16 v1; // di
unsigned __int16 result; // ax
__int16 v3; // cx
int v4; // edx

v0 = (unsigned __int8)byte_2A2;
v1 = (unsigned __int8)rand8[(unsigned __int8)byte_2A2];
result = word_2A0 + v1 * (unsigned __int8)word_2A5;
v3 = HIBYTE(result) + v1 * HIBYTE(word_2A5);
rand8[(unsigned __int8)byte_2A2] = result;
word_2A0 = v3;
v4 = v0 + 1;
if ( (unsigned __int8)byte_2A4 <= v4 )
LOBYTE(v4) = 0;
byte_2A2 = v4;
return result;
}

canonical_decompiled_code:
unsigned __int16 func7()
{
int v0; // edx
__int16 v1; // di
unsigned __int16 result; // ax
__int16 v3; // cx
int v4; // edx

v0 = (unsigned __int8)byte_2A2;
v1 = (unsigned __int8)rand8[(unsigned __int8)byte_2A2];
result = word_2A0 + v1 * (unsigned __int8)word_2A5;
v3 = HIBYTE(result) + v1 * HIBYTE(word_2A5);
rand8[(unsigned __int8)byte_2A2] = result;
word_2A0 = v3;
v4 = v0 + 1;
if ( (unsigned __int8)byte_2A4 <= v4 )
LOBYTE(v4) = 0;
byte_2A2 = v4;
return result;
}

original_code:
uint8_t rand8_16bit(void)
{
    int i = rand8.i;
    uint8_t x = rand8.state[i];
    uint16_t c = rand8.c;
    uint16_t t;
    t = (uint16_t)((uint8_t)(x) * (uint8_t)(rand8.mul_lo)) + c;
    c = t >> 8;
    c += (uint16_t)((uint8_t)(x) * (uint8_t)(rand8.mul_hi));
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}

canonical_original_code:
unsigned char rand8_16bit()
{
    int i = rand8.i;
    unsigned char x = rand8.state[i];
    unsigned short c = rand8.c;
    unsigned short t;
    t = (unsigned short)((unsigned char)(x) * (unsigned char)(rand8.mul_lo)) + c;
    c = t >> 8;
    c += (unsigned short)((unsigned char)(x) * (unsigned char)(rand8.mul_hi));
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}


decompiled_code:
__int64 rand16_16bit()
{
unsigned __int8 v0; // bl
int v1; // eax

v0 = rand8_16bit();
LOWORD(v1) = rand8_16bit();
return (unsigned int)v0 + (v1 << 8);
}

canonical_decompiled_code:
__int64 func8()
{
unsigned __int8 v0; // bl
int v1; // eax

v0 = func7();
LOWORD(v1) = func7();
return (unsigned int)v0 + (v1 << 8);
}

original_code:
uint16_t rand16_16bit(void)
{
    uint8_t x, y;
    x = rand8_16bit();
    y = rand8_16bit();
    return ((uint16_t)y << 8) + x;
}

canonical_original_code:
unsigned short rand16_16bit()
{
    unsigned char x; unsigned char y;
    x = rand8_16bit();
    y = rand8_16bit();
    return ((unsigned short)y << 8) + x;
}


decompiled_code:
__int64 rand32_16bit()
{
unsigned __int16 v0; // bx

v0 = rand16_16bit();
return v0 + ((unsigned int)rand16_16bit() << 16);
}

canonical_decompiled_code:
__int64 func9()
{
unsigned __int16 v0; // bx

v0 = func8();
return v0 + ((unsigned int)func8() << 16);
}

original_code:
uint32_t rand32_16bit(void)
{
    uint16_t x, y;
    x = rand16_16bit();
    y = rand16_16bit();
    return ((uint32_t)y << 16) + x;
}

canonical_original_code:
unsigned int rand32_16bit()
{
    unsigned short x; unsigned short y;
    x = rand16_16bit();
    y = rand16_16bit();
    return ((unsigned int)y << 16) + x;
}


decompiled_code:
__int64 rand8_8z8bit()
{
int v0; // edx
__int64 result; // rax
int v2; // edx

v0 = (unsigned __int8)byte_2A2;
result = (unsigned __int16)((unsigned __int8)rand8[(unsigned __int8)byte_2A2] * (unsigned __int8)word_2A5)
+ (unsigned __int16)word_2A0
+ (((unsigned __int8)byte_2A3
+ (unsigned __int8)rand8[(unsigned __int8)byte_2A2] * (unsigned int)HIBYTE(word_2A5)) << 16);
rand8[(unsigned __int8)byte_2A2] = rand8[(unsigned __int8)byte_2A2] * word_2A5 + word_2A0;
word_2A0 = (unsigned int)result >> 8;
byte_2A3 = BYTE3(result);
v2 = v0 + 1;
if ( (unsigned __int8)byte_2A4 <= v2 )
LOBYTE(v2) = 0;
byte_2A2 = v2;
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // edx
__int64 result; // rax
int v2; // edx

v0 = (unsigned __int8)byte_2A2;
result = (unsigned __int16)((unsigned __int8)rand8[(unsigned __int8)byte_2A2] * (unsigned __int8)word_2A5)
+ (unsigned __int16)word_2A0
+ (((unsigned __int8)byte_2A3
+ (unsigned __int8)rand8[(unsigned __int8)byte_2A2] * (unsigned int)HIBYTE(word_2A5)) << 16);
rand8[(unsigned __int8)byte_2A2] = rand8[(unsigned __int8)byte_2A2] * word_2A5 + word_2A0;
word_2A0 = (unsigned int)result >> 8;
byte_2A3 = BYTE3(result);
v2 = v0 + 1;
if ( (unsigned __int8)byte_2A4 <= v2 )
LOBYTE(v2) = 0;
byte_2A2 = v2;
return result;
}

original_code:
uint8_t rand8_8z8bit(void)
{
    int i = rand8.i;
    uint8_t x = rand8.state[i];
    uint16_t c0 = rand8.c;
    uint8_t c1 = rand8.c1;
    uint32_t t;
    t = (uint16_t)((uint8_t)(x) * (uint8_t)(rand8.mul_lo)) + (uint32_t)c0;
    t += (uint32_t)((uint16_t)((uint8_t)(x) * (uint8_t)(rand8.mul_hi)) + c1) << 16;
    c0 = t >> 8;
    c1 = t >> 24;
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c0;
    rand8.c1 = c1;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}

canonical_original_code:
unsigned char rand8_8z8bit()
{
    int i = rand8.i;
    unsigned char x = rand8.state[i];
    unsigned short c0 = rand8.c;
    unsigned char c1 = rand8.c1;
    unsigned int t;
    t = (unsigned short)((unsigned char)(x) * (unsigned char)(rand8.mul_lo)) + (unsigned int)c0;
    t += (unsigned int)((unsigned short)((unsigned char)(x) * (unsigned char)(rand8.mul_hi)) + c1) << 16;
    c0 = t >> 8;
    c1 = t >> 24;
    x = t & 255;
    rand8.state[i] = x;
    rand8.c = c0;
    rand8.c1 = c1;
    if (++i >= rand8.r)
        i = 0;
    rand8.i = i;
    return x;
}


decompiled_code:
__int64 rand16_8z8bit()
{
unsigned __int8 v0; // bl

v0 = rand8_8z8bit();
return v0 + ((unsigned int)rand8_8z8bit() << 8);
}

canonical_decompiled_code:
__int64 func11()
{
unsigned __int8 v0; // bl

v0 = func10();
return v0 + ((unsigned int)func10() << 8);
}

original_code:
uint16_t rand16_8z8bit(void)
{
    uint8_t x, y;
    x = rand8_8z8bit();
    y = rand8_8z8bit();
    return ((uint16_t)y << 8) + x;
}

canonical_original_code:
unsigned short rand16_8z8bit()
{
    unsigned char x; unsigned char y;
    x = rand8_8z8bit();
    y = rand8_8z8bit();
    return ((unsigned short)y << 8) + x;
}


decompiled_code:
__int64 rand32_8z8bit()
{
unsigned __int16 v0; // bx

v0 = rand16_8z8bit();
return v0 + ((unsigned int)rand16_8z8bit() << 16);
}

canonical_decompiled_code:
__int64 func12()
{
unsigned __int16 v0; // bx

v0 = func11();
return v0 + ((unsigned int)func11() << 16);
}

original_code:
uint32_t rand32_8z8bit(void)
{
    uint16_t x, y;
    x = rand16_8z8bit();
    y = rand16_8z8bit();
    return ((uint32_t)y << 16) + x;
}

canonical_original_code:
unsigned int rand32_8z8bit()
{
    unsigned short x; unsigned short y;
    x = rand16_8z8bit();
    y = rand16_8z8bit();
    return ((unsigned int)y << 16) + x;
}


decompiled_code:
unsigned __int64 __fastcall p32(unsigned __int16 a1, unsigned __int16 a2, int a3, unsigned __int64 a4, char a5)
{
unsigned __int16 v6; // r9
int v7; // er11
unsigned int v8; // er10
unsigned int v9; // eax
__int64 v10; // rdi
unsigned __int64 v11; // rdx
unsigned __int64 v12; // rdx

v6 = a2;
v7 = ~(-2 << (a5 - 1));
v8 = v7 & a3;
v9 = v7 & a3;
v10 = 0LL;
while ( 1 )
{
v11 = a1 * (unsigned __int64)v9 + a2;
v9 = v11 & v7;
v12 = v11 >> a5;
a2 = v12;
if ( ++v10 >= a4 )
return a4;
if ( v6 > (unsigned __int16)v12 )
return 0LL;
if ( v8 > v9 && v6 == (_WORD)v12 )
break;
if ( v6 == (_WORD)v12 && v8 == v9 )
return v10;
}
return 0LL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int16 a1, unsigned __int16 a2, int a3, unsigned __int64 a4, char a5)
{
unsigned __int16 v6; // r9
int v7; // er11
unsigned int v8; // er10
unsigned int v9; // eax
__int64 v10; // rdi
unsigned __int64 v11; // rdx
unsigned __int64 v12; // rdx

v6 = a2;
v7 = ~(-2 << (a5 - 1));
v8 = v7 & a3;
v9 = v7 & a3;
v10 = 0LL;
while ( 1 )
{
v11 = a1 * (unsigned __int64)v9 + a2;
v9 = v11 & v7;
v12 = v11 >> a5;
a2 = v12;
if ( ++v10 >= a4 )
return a4;
if ( v6 > (unsigned __int16)v12 )
return 0LL;
if ( v8 > v9 && v6 == (_WORD)v12 )
break;
if ( v6 == (_WORD)v12 && v8 == v9 )
return v10;
}
return 0LL;
}

original_code:
static uint64_t p32(uint16_t a, uint16_t c, uint32_t x, uint64_t b, int s)
{
    uint32_t m = ~(0xfffffffe << (s - 1));
    uint16_t cc = c;
    uint64_t xx;
    uint64_t p = 0;
    xx = x &= m;
    do
    {
        uint64_t t = (uint64_t)x * a + c;
        x = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && x < xx))
            return 0;
    } while (x != xx || c != cc);
    return p;
}

canonical_original_code:
static unsigned long p32(unsigned short a, unsigned short c, unsigned int x, unsigned long b, int s)
{
    unsigned int m = ~(0xfffffffe << (s - 1));
    unsigned short cc = c;
    unsigned long xx;
    unsigned long p = 0;
    xx = x &= m;
    do
    {
        unsigned long t = (uint64_t)x * a + c;
        x = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && x < xx))
            return 0;
    } while (x != xx || c != cc);
    return p;
}

variable_types:
x
unsigned int

variable_types:
b
unsigned long

variable_types: s int

variable_types:
m
unsigned int

variable_types:
cc
unsigned short

variable_types:
xx
unsigned long

variable_types:
p
unsigned long

variable_types:
t
unsigned long


decompiled_code:
unsigned __int64 __fastcall p56(unsigned __int16 a1, unsigned __int16 a2, __int64 a3, unsigned __int64 a4, char a5)
{
unsigned __int16 v6; // r9
__int64 v7; // r11
unsigned __int64 v8; // rdx
unsigned __int64 v9; // r10
__int64 v10; // rdi
unsigned __int64 v11; // rax
unsigned __int64 v12; // rax

v6 = a2;
v7 = ~(-2LL << (a5 - 1));
v8 = v7 & a3;
v9 = v8;
v10 = 0LL;
while ( 1 )
{
v11 = a1 * v8 + a2;
v8 = v11 & v7;
v12 = v11 >> a5;
a2 = v12;
if ( ++v10 >= a4 )
return a4;
if ( v6 > (unsigned __int16)v12 )
return 0LL;
if ( v6 == (_WORD)v12 && v9 > v8 )
break;
if ( v9 == v8 && v6 == (_WORD)v12 )
return v10;
}
return 0LL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int16 a1, unsigned __int16 a2, __int64 a3, unsigned __int64 a4, char a5)
{
unsigned __int16 v6; // r9
__int64 v7; // r11
unsigned __int64 v8; // rdx
unsigned __int64 v9; // r10
__int64 v10; // rdi
unsigned __int64 v11; // rax
unsigned __int64 v12; // rax

v6 = a2;
v7 = ~(-2LL << (a5 - 1));
v8 = v7 & a3;
v9 = v8;
v10 = 0LL;
while ( 1 )
{
v11 = a1 * v8 + a2;
v8 = v11 & v7;
v12 = v11 >> a5;
a2 = v12;
if ( ++v10 >= a4 )
return a4;
if ( v6 > (unsigned __int16)v12 )
return 0LL;
if ( v6 == (_WORD)v12 && v9 > v8 )
break;
if ( v9 == v8 && v6 == (_WORD)v12 )
return v10;
}
return 0LL;
}

original_code:
static uint64_t p56(uint16_t a, uint16_t c, uint64_t x, uint64_t b, int s)
{
    uint64_t m = ~(0xfffffffffffffffeull << (s - 1));
    uint16_t cc = c;
    uint64_t xx;
    uint64_t p = 0;
    xx = x &= m;
    do
    {
        uint64_t t = x * a + c;
        x = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && x < xx))
            return 0;
    } while (x != xx || c != cc);
    return p;
}

canonical_original_code:
static unsigned long p56(unsigned short a, unsigned short c, unsigned long x, unsigned long b, int s)
{
    unsigned long m = ~(0xfffffffffffffffeull << (s - 1));
    unsigned short cc = c;
    unsigned long xx;
    unsigned long p = 0;
    xx = x &= m;
    do
    {
        unsigned long t = x * a + c;
        x = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && x < xx))
            return 0;
    } while (x != xx || c != cc);
    return p;
}

variable_types:
c
unsigned short

variable_types:
x
unsigned long

variable_types:
m
unsigned long


decompiled_code:
unsigned __int64 __fastcall p64(unsigned __int16 a1, unsigned __int16 a2, __int64 a3, unsigned __int64 a4, char a5)
{
unsigned __int16 v6; // r10
int v7; // er11
unsigned int v8; // ebp
unsigned __int64 v9; // r12
char v10; // cl
unsigned int v11; // er13
__int64 v12; // r8
__int64 v13; // r9
unsigned __int64 v14; // rdi
unsigned __int64 v15; // rax
unsigned __int64 v16; // rax

v6 = a2;
v7 = ~(-2 << (a5 - 1));
v8 = v7 & HIDWORD(a3);
v9 = (unsigned int)a3;
v10 = ((a5 - 1) & 0x1F) + 1;
v11 = v7 & HIDWORD(a3);
v12 = 0LL;
v13 = a1;
while ( 1 )
{
do
{
do
{
v14 = v13 * (unsigned int)a3 + a2;
LODWORD(a3) = v13 * a3 + a2;
v15 = HIDWORD(v14) + v13 * v11;
v11 = v15 & v7;
v16 = v15 >> v10;
a2 = v16;
if ( ++v12 >= a4 )
return a4;
if ( v6 > (unsigned __int16)v16 )
return 0LL;
}
while ( v6 != (_WORD)v16 );
if ( v8 > v11 )
return 0LL;
}
while ( v8 != v11 );
if ( v9 > (unsigned int)v14 )
break;
if ( v9 == (unsigned int)v14 )
return v12;
}
return 0LL;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int16 a1, unsigned __int16 a2, __int64 a3, unsigned __int64 a4, char a5)
{
unsigned __int16 v6; // r10
int v7; // er11
unsigned int v8; // ebp
unsigned __int64 v9; // r12
char v10; // cl
unsigned int v11; // er13
__int64 v12; // r8
__int64 v13; // r9
unsigned __int64 v14; // rdi
unsigned __int64 v15; // rax
unsigned __int64 v16; // rax

v6 = a2;
v7 = ~(-2 << (a5 - 1));
v8 = v7 & HIDWORD(a3);
v9 = (unsigned int)a3;
v10 = ((a5 - 1) & 0x1F) + 1;
v11 = v7 & HIDWORD(a3);
v12 = 0LL;
v13 = a1;
while ( 1 )
{
do
{
do
{
v14 = v13 * (unsigned int)a3 + a2;
LODWORD(a3) = v13 * a3 + a2;
v15 = HIDWORD(v14) + v13 * v11;
v11 = v15 & v7;
v16 = v15 >> v10;
a2 = v16;
if ( ++v12 >= a4 )
return a4;
if ( v6 > (unsigned __int16)v16 )
return 0LL;
}
while ( v6 != (_WORD)v16 );
if ( v8 > v11 )
return 0LL;
}
while ( v8 != v11 );
if ( v9 > (unsigned int)v14 )
break;
if ( v9 == (unsigned int)v14 )
return v12;
}
return 0LL;
}

canonical_original_code:
static unsigned long p64(unsigned short a, unsigned short c, unsigned long x, unsigned long b, int s)
{
    unsigned int m = ~(0xfffffffe << ((s - 1) & 31));
    unsigned int x0 = x & 0xffffffff; unsigned int x1 = (x >> 32) & m;
    unsigned short cc = c;
    unsigned long xx0 = x0;
    unsigned long xx1 = x1;
    unsigned long p = 0;
    s = ((s - 1) & 31) + 1;
    do
    {
        unsigned long t = (uint64_t)x0 * a + c;
        x0 = (unsigned int)t;
        c = t >> 32;
        t = (unsigned long)x1 * a + c;
        x1 = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && (x1 < xx1 || (x1 <= xx1 && x0 < xx0))))
            return 0;
    } while (x0 != xx0 || x1 != xx1 || c != cc);
    return p;
}

variable_types:
a
unsigned short


decompiled_code:
__int64 __fastcall p96(__int64 a1, unsigned __int16 a2, unsigned __int64 a3, unsigned __int64 a4, char a5)
{
unsigned __int16 v5; // r15
int v8; // er12
unsigned __int64 v9; // r14
unsigned __int64 v10; // rbp
char v11; // cl
unsigned __int64 v12; // rax
unsigned __int64 v13; // rsi
unsigned int v14; // er9
unsigned __int64 v15; // rdx
unsigned int v16; // er11
unsigned int v17; // ebx
__int64 v18; // r8
unsigned __int64 v19; // rdx

v5 = a2;
v8 = ~(-2 << (a5 - 1));
v9 = HIDWORD(a3);
v10 = (unsigned int)a3;
v11 = ((a5 - 1) & 0x1F) + 1;
a1 = (unsigned __int16)a1;
LODWORD(v12) = (unsigned __int16)a1 * (_DWORD)a3 + a2;
v13 = (((unsigned __int16)a1 * (unsigned __int64)(unsigned int)a3 + a2) >> 32) + (unsigned __int16)a1 * HIDWORD(a3);
v14 = HIDWORD(v13) & v8;
v15 = HIDWORD(v13) >> v11;
if ( a4 <= 1 )
return a4;
v16 = v12;
v17 = v13;
if ( v5 <= (unsigned __int16)v15 )
{
v18 = 1LL;
while ( 1 )
{
if ( a2 >= (unsigned __int16)v15 && !v14 )
{
if ( v9 > (unsigned int)v13 )
return 0LL;
if ( v9 == (unsigned int)v13 && v10 > (unsigned int)v12 )
return 0LL;
}
if ( v10 == (unsigned int)v12 && v14 == 0 && (unsigned int)v13 == v9 && a2 == (_WORD)v15 )
return v18;
v12 = a1 * v16 + (unsigned __int16)v15;
v16 = a1 * v16 + (unsigned __int16)v15;
v13 = a1 * v17 + HIDWORD(v12);
v17 = a1 * v17 + HIDWORD(v12);
v19 = a1 * v14 + HIDWORD(v13);
v14 = v19 & v8;
v15 = v19 >> v11;
if ( ++v18 == a4 )
return a4;
if ( a2 > (unsigned __int16)v15 )
return 0LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int16 a2, unsigned __int64 a3, unsigned __int64 a4, char a5)
{
unsigned __int16 v5; // r15
int v8; // er12
unsigned __int64 v9; // r14
unsigned __int64 v10; // rbp
char v11; // cl
unsigned __int64 v12; // rax
unsigned __int64 v13; // rsi
unsigned int v14; // er9
unsigned __int64 v15; // rdx
unsigned int v16; // er11
unsigned int v17; // ebx
__int64 v18; // r8
unsigned __int64 v19; // rdx

v5 = a2;
v8 = ~(-2 << (a5 - 1));
v9 = HIDWORD(a3);
v10 = (unsigned int)a3;
v11 = ((a5 - 1) & 0x1F) + 1;
a1 = (unsigned __int16)a1;
LODWORD(v12) = (unsigned __int16)a1 * (_DWORD)a3 + a2;
v13 = (((unsigned __int16)a1 * (unsigned __int64)(unsigned int)a3 + a2) >> 32) + (unsigned __int16)a1 * HIDWORD(a3);
v14 = HIDWORD(v13) & v8;
v15 = HIDWORD(v13) >> v11;
if ( a4 <= 1 )
return a4;
v16 = v12;
v17 = v13;
if ( v5 <= (unsigned __int16)v15 )
{
v18 = 1LL;
while ( 1 )
{
if ( a2 >= (unsigned __int16)v15 && !v14 )
{
if ( v9 > (unsigned int)v13 )
return 0LL;
if ( v9 == (unsigned int)v13 && v10 > (unsigned int)v12 )
return 0LL;
}
if ( v10 == (unsigned int)v12 && v14 == 0 && (unsigned int)v13 == v9 && a2 == (_WORD)v15 )
return v18;
v12 = a1 * v16 + (unsigned __int16)v15;
v16 = a1 * v16 + (unsigned __int16)v15;
v13 = a1 * v17 + HIDWORD(v12);
v17 = a1 * v17 + HIDWORD(v12);
v19 = a1 * v14 + HIDWORD(v13);
v14 = v19 & v8;
v15 = v19 >> v11;
if ( ++v18 == a4 )
return a4;
if ( a2 > (unsigned __int16)v15 )
return 0LL;
}
}
return 0LL;
}

canonical_original_code:
static unsigned long p96(unsigned short a, unsigned short c, unsigned long x, unsigned long b, int s)
{
    unsigned int m = ~(0xfffffffe << ((s - 1) & 31));
    unsigned int x0 = x & 0xffffffff; unsigned int x1 = x >> 32; unsigned int x2 = 0;
    unsigned short cc = c;
    unsigned long xx0 = x0;
    unsigned long xx1 = x1;
    unsigned long xx2 = x2;
    unsigned long p = 0;
    s = ((s - 1) & 31) + 1;
    do
    {
        unsigned long t = (uint64_t)x0 * a + c;
        x0 = (unsigned int)t;
        c = t >> 32;
        t = (unsigned long)x1 * a + c;
        x1 = (unsigned int)t;
        c = t >> 32;
        t = (unsigned long)x2 * a + c;
        x2 = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && (x2 < xx2 || (x2 <= xx2 && (x1 < xx1 || (x1 <= xx1 && x0 < xx0))))))
            return 0;
    } while (x0 != xx0 || x1 != xx1 || x2 != xx2 || c != cc);
    return p;
}


decompiled_code:
__int64 __fastcall p128(unsigned __int16 a1, unsigned __int16 a2, unsigned __int64 a3, unsigned __int64 a4, char a5)
{
unsigned __int64 v7; // r14
unsigned __int64 v8; // rbp
char v9; // cl
__int64 v10; // r8
unsigned __int64 v11; // rsi
unsigned __int64 v12; // rdi
unsigned __int64 v13; // rax
unsigned int v14; // er11
__int64 v15; // r10
unsigned __int64 v16; // rdx
unsigned int v17; // er9
unsigned __int64 v18; // rdx
unsigned __int64 v19; // rdx
unsigned int v21; // [rsp+0h] [rbp-38h]
int v22; // [rsp+4h] [rbp-34h]

v22 = ~(-2 << (a5 - 1));
v7 = HIDWORD(a3);
v8 = (unsigned int)a3;
v9 = ((a5 - 1) & 0x1F) + 1;
v10 = a1;
v11 = a1 * (unsigned __int64)(unsigned int)a3 + a2;
v21 = v11;
v12 = HIDWORD(v11) + a1 * HIDWORD(a3);
v13 = HIDWORD(v12);
if ( a4 > 1 )
{
v14 = v12;
v15 = 1LL;
LOWORD(v16) = 0;
v17 = 0;
while ( 1 )
{
if ( a2 > (unsigned __int16)v16 )
return 0LL;
if ( !(v17 | (unsigned int)v13) && a2 == (_WORD)v16 )
{
if ( v7 > (unsigned int)v12 )
return 0LL;
if ( v7 == (unsigned int)v12 && v8 > (unsigned int)v11 )
return 0LL;
}
if ( v8 == (unsigned int)v11 && (v17 | (unsigned int)v13) == 0 && (unsigned int)v12 == v7 && a2 == (_WORD)v16 )
return v15;
v11 = (unsigned __int16)v16 + v10 * v21;
v21 = (unsigned __int16)v16 + v10 * v21;
v12 = v10 * v14 + HIDWORD(v11);
v14 = v10 * v14 + HIDWORD(v11);
v18 = v10 * (unsigned int)v13 + HIDWORD(v12);
LODWORD(v13) = v10 * v13 + HIDWORD(v12);
v19 = v10 * v17 + HIDWORD(v18);
v17 = v19 & v22;
v16 = v19 >> v9;
if ( ++v15 == a4 )
return a4;
}
}
return a4;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 a1, unsigned __int16 a2, unsigned __int64 a3, unsigned __int64 a4, char a5)
{
unsigned __int64 v7; // r14
unsigned __int64 v8; // rbp
char v9; // cl
__int64 v10; // r8
unsigned __int64 v11; // rsi
unsigned __int64 v12; // rdi
unsigned __int64 v13; // rax
unsigned int v14; // er11
__int64 v15; // r10
unsigned __int64 v16; // rdx
unsigned int v17; // er9
unsigned __int64 v18; // rdx
unsigned __int64 v19; // rdx
unsigned int v21; // [rsp+0h] [rbp-38h]
int v22; // [rsp+4h] [rbp-34h]

v22 = ~(-2 << (a5 - 1));
v7 = HIDWORD(a3);
v8 = (unsigned int)a3;
v9 = ((a5 - 1) & 0x1F) + 1;
v10 = a1;
v11 = a1 * (unsigned __int64)(unsigned int)a3 + a2;
v21 = v11;
v12 = HIDWORD(v11) + a1 * HIDWORD(a3);
v13 = HIDWORD(v12);
if ( a4 > 1 )
{
v14 = v12;
v15 = 1LL;
LOWORD(v16) = 0;
v17 = 0;
while ( 1 )
{
if ( a2 > (unsigned __int16)v16 )
return 0LL;
if ( !(v17 | (unsigned int)v13) && a2 == (_WORD)v16 )
{
if ( v7 > (unsigned int)v12 )
return 0LL;
if ( v7 == (unsigned int)v12 && v8 > (unsigned int)v11 )
return 0LL;
}
if ( v8 == (unsigned int)v11 && (v17 | (unsigned int)v13) == 0 && (unsigned int)v12 == v7 && a2 == (_WORD)v16 )
return v15;
v11 = (unsigned __int16)v16 + v10 * v21;
v21 = (unsigned __int16)v16 + v10 * v21;
v12 = v10 * v14 + HIDWORD(v11);
v14 = v10 * v14 + HIDWORD(v11);
v18 = v10 * (unsigned int)v13 + HIDWORD(v12);
LODWORD(v13) = v10 * v13 + HIDWORD(v12);
v19 = v10 * v17 + HIDWORD(v18);
v17 = v19 & v22;
v16 = v19 >> v9;
if ( ++v15 == a4 )
return a4;
}
}
return a4;
}

canonical_original_code:
static unsigned long p128(unsigned short a, unsigned short c, unsigned long x, unsigned long b, int s)
{
    unsigned int m = ~(0xfffffffe << ((s - 1) & 31));
    unsigned int x0 = x & 0xffffffff; unsigned int x1 = x >> 32; unsigned int x2 = 0; unsigned int x3 = 0;
    unsigned short cc = c;
    unsigned long xx0 = x0;
    unsigned long xx1 = x1;
    unsigned long xx2 = x2;
    unsigned long xx3 = x3;
    unsigned long p = 0;
    s = ((s - 1) & 31) + 1;
    do
    {
        unsigned long t = (uint64_t)x0 * a + c;
        x0 = (unsigned int)t;
        c = t >> 32;
        t = (unsigned long)x1 * a + c;
        x1 = (unsigned int)t;
        c = t >> 32;
        t = (unsigned long)x2 * a + c;
        x2 = (unsigned int)t;
        c = t >> 32;
        t = (unsigned long)x3 * a + c;
        x3 = t & m;
        c = t >> s;
        p++;
        if (p >= b)
            return b;
        if (c < cc || (c <= cc && (x3 < xx3 || (x3 <= xx3 && (x2 < xx2 || (x2 <= xx2 && (x1 < xx1 || (x1 <= xx1 && x0 < xx0))))))))
            return 0;
    } while (x0 != xx0 || x1 != xx1 || x2 != xx2 || x3 != xx3 || c != cc);
    return p;
}


period

decompiled_code:
unsigned __int64 __fastcall period(unsigned __int16 a1, unsigned __int16 a2, unsigned __int64 a3, unsigned __int8 a4, unsigned __int64 a5)
{
char v6; // r8
unsigned __int64 result; // rax

v6 = 8 * a4;
switch ( a4 )
{
case 1u:
case 2u:
case 3u:
case 4u:
result = p32(a1, a2, a3, a5, v6);
break;
case 5u:
case 6u:
result = p56(a1, a2, a3, a5, v6);
break;
case 7u:
case 8u:
result = p64(a1, a2, a3, a5, v6);
break;
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
result = p96(a1, a2, a3, a5, v6);
break;
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
result = p128(a1, a2, a3, a5, v6);
break;
default:
fprintf(stderr, "unsupported r=%d.\n", a4);
exit(-1);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(unsigned __int16 a1, unsigned __int16 a2, unsigned __int64 a3, unsigned __int8 a4, unsigned __int64 a5)
{
char v6; // r8
unsigned __int64 result; // rax

v6 = 8 * a4;
switch ( a4 )
{
case 1u:
case 2u:
case 3u:
case 4u:
result = func0(a1, a2, a3, a5, v6);
break;
case 5u:
case 6u:
result = func1(a1, a2, a3, a5, v6);
break;
case 7u:
case 8u:
result = func2(a1, a2, a3, a5, v6);
break;
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
result = func3(a1, a2, a3, a5, v6);
break;
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
result = func4(a1, a2, a3, a5, v6);
break;
default:
fprintf(stderr, "unsupported r=%d.\n", a4);
exit(-1);
}
return result;
}

original_code:
static uint64_t period(uint16_t a, uint16_t c, uint64_t x, uint8_t r, uint64_t b)
{
    int s = r * 8;
    switch (r)
    {
    case 1: case 2: case 3: case 4:
        return p32(a, c, x, b, s);
    case 5: case 6:
        return p56(a, c, x, b, s);
    case 7: case 8:
        return p64(a, c, x, b, s);
    case 9: case 10: case 11: case 12:
        return p96(a, c, x, b, s);
    case 13: case 14: case 15: case 16:
        return p128(a, c, x, b, s);
    }
    fprintf(stderr, "unsupported r=%d.\n", r);
    exit(-1);
    return 0;
}

canonical_original_code:
static unsigned long period(unsigned short a, unsigned short c, unsigned long x, unsigned char r, unsigned long b)
{
    int s = r * 8;
    switch (r)
    {
    case 1: case 2: case 3: case 4:
        return p32(a, c, x, b, s);
    case 5: case 6:
        return p56(a, c, x, b, s);
    case 7: case 8:
        return p64(a, c, x, b, s);
    case 9: case 10: case 11: case 12:
        return p96(a, c, x, b, s);
    case 13: case 14: case 15: case 16:
        return p128(a, c, x, b, s);
    }
    fprintf(stderr, "unsupported r=%d.\n", r);
    exit(-1);
    return 0;
}

variable_types:
r
unsigned char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // r15
unsigned __int8 v5; // r14
unsigned __int16 v6; // r13
int v7; // eax
unsigned int *v9; // r15
__int64 v10; // rdx
int v11; // [rsp+Ch] [rbp-3Ch]

v3 = 0LL;
v4 = 0LL;
v11 = 0;
v5 = 0;
v6 = 0;
while ( 2 )
{
v7 = getopt(argc, (char *const *)argv, "w:n:u:a:r:qh");
if ( v7 != -1 )
{
switch ( v7 )
{
case 'a':
v6 = strtoul(optarg, 0LL, 0);
continue;
case 'h':
usage();
return 0;
case 'n':
v3 = strtol(optarg, 0LL, 0);
v4 = (unsigned int)((_DWORD)&multiplier_table + 1056);
continue;
case 'q':
v11 = 1;
continue;
case 'r':
v5 = strtoul(optarg, 0LL, 0);
continue;
case 'u':
v3 = strtol(optarg, 0LL, 0);
v4 = (unsigned int)((_DWORD)&multiplier_table + 1584);
continue;
case 'w':
v3 = strtol(optarg, 0LL, 0);
v4 = (unsigned int)((_DWORD)&multiplier_table + 528);
continue;
default:
fwrite("Invalid argument.\n", 1uLL, 0x12uLL, stderr);
usage();
exit(1);
}
}
break;
}
if ( (unsigned __int8)(v5 - 1) > 0x1Fu )
{
fwrite("Out-of-range lag value.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( !v6 )
{
if ( !v4 )
{
fwrite("Must choose multiplier.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( v3 < 0 )
v3 += *(int *)(v4 + 16LL * v5);
v9 = (unsigned int *)(16LL * v5 + v4);
v10 = *v9;
if ( (unsigned int)v10 <= (unsigned int)v3 )
{
if ( (int)v10 <= 0 )
fprintf(stderr, "No known lag-%d multipliers.\n", v5);
else
fprintf(stderr, "Only %d known lag-%d multipliers.\n", v10, v5);
exit(1);
}
v6 = *(_WORD *)(*((_QWORD *)v9 + 1) + 4 * v3);
}
printf("b=256 a=0x%04x r=%d\n", v6, v5);
if ( v6 + 255 * (unsigned __int8)v6 > 0x10000 )
{
fwrite("This multiplier could overflow internal arithmetic.\n", 1uLL, 0x34uLL, stderr);
exit(1);
}
test_loop(v6, v5, v11);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // r15
unsigned __int8 v5; // r14
unsigned __int16 v6; // r13
int v7; // eax
unsigned int *v9; // r15
__int64 v10; // rdx
int v11; // [rsp+Ch] [rbp-3Ch]

v3 = 0LL;
v4 = 0LL;
v11 = 0;
v5 = 0;
v6 = 0;
while ( 2 )
{
v7 = getopt(argc, (char *const *)argv, "w:n:u:a:r:qh");
if ( v7 != -1 )
{
switch ( v7 )
{
case 'a':
v6 = strtoul(optarg, 0LL, 0);
continue;
case 'h':
func6();
return 0;
case 'n':
v3 = strtol(optarg, 0LL, 0);
v4 = (unsigned int)((_DWORD)&multiplier_table + 1056);
continue;
case 'q':
v11 = 1;
continue;
case 'r':
v5 = strtoul(optarg, 0LL, 0);
continue;
case 'u':
v3 = strtol(optarg, 0LL, 0);
v4 = (unsigned int)((_DWORD)&multiplier_table + 1584);
continue;
case 'w':
v3 = strtol(optarg, 0LL, 0);
v4 = (unsigned int)((_DWORD)&multiplier_table + 528);
continue;
default:
fwrite("Invalid argument.\n", 1uLL, 0x12uLL, stderr);
func6();
exit(1);
}
}
break;
}
if ( (unsigned __int8)(v5 - 1) > 0x1Fu )
{
fwrite("Out-of-range lag value.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( !v6 )
{
if ( !v4 )
{
fwrite("Must choose multiplier.\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( v3 < 0 )
v3 += *(int *)(v4 + 16LL * v5);
v9 = (unsigned int *)(16LL * v5 + v4);
v10 = *v9;
if ( (unsigned int)v10 <= (unsigned int)v3 )
{
if ( (int)v10 <= 0 )
fprintf(stderr, "No known lag-%d multipliers.\n", v5);
else
fprintf(stderr, "Only %d known lag-%d multipliers.\n", v10, v5);
exit(1);
}
v6 = *(_WORD *)(*((_QWORD *)v9 + 1) + 4 * v3);
}
printf("b=256 a=0x%04x r=%d\n", v6, v5);
if ( v6 + 255 * (unsigned __int8)v6 > 0x10000 )
{
fwrite("This multiplier could overflow internal arithmetic.\n", 1uLL, 0x34uLL, stderr);
exit(1);
}
func7(v6, v5, v11);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    uint16_t a = 0;
    uint8_t r = 0;
    int quick = 0;
    tabptr_t const *table = ((void *)0);
    long tab_index = 0;
    uint8_t a_lo;
    int optc;
    while ((optc = getopt(argc, argv, "w:n:u:a:r:qh")) != -1)
        switch (optc)
        {
        case 'w':
            table = multiplier_table[WIDE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'n':
            table = multiplier_table[NARROW_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'u':
            table = multiplier_table[UNSAFE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'a':
            a = strtoul(optarg, ((void *)0), 0);
            break;
        case 'r':
            r = strtoul(optarg, ((void *)0), 0);
            break;
        case 'q': quick = 1;
            break;
        case 'h':
            usage();
            return 0;
        default:
            fprintf(stderr, "Invalid argument.\n");
            usage();
            exit(1);
        }
    if (r < 1 || r > 32)
    {
        fprintf(stderr, "Out-of-range lag value.\n");
        exit(1);
    }
    if (a == 0)
    {
        if (table == ((void *)0))
        {
            fprintf(stderr, "Must choose multiplier.\n");
            exit(1);
        }
        if (tab_index < 0)
            tab_index += table[r].len;
        if ((unsigned)tab_index >= table[r].len)
        {
            if (table[r].len > 0)
                fprintf(stderr, "Only %d known lag-%d multipliers.\n", table[r].len, r);
            else
                fprintf(stderr, "No known lag-%d multipliers.\n", r);
            exit(1);
        }
        a = table[r].tab[tab_index];
    }
    a_lo = a & 0xff;
    printf("b=256 a=0x%04x r=%d\n", a, r);
    if (255 * a_lo + a - 1 > 0xffff)
    {
        fprintf(stderr, "This multiplier could overflow internal arithmetic.\n");
        exit(1);
    }
    argc -= optind;
    argv += optind;
    test_loop(a, r, quick);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned short a = 0;
    unsigned char r = 0;
    int quick = 0;
    struct tabptr_t *table = ((void *)0);
    long tab_index = 0;
    unsigned char a_lo;
    int optc;
    while ((optc = getopt(argc, argv, "w:n:u:a:r:qh")) != -1)
        switch (optc)
        {
        case 'w':
            table = multiplier_table[WIDE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'n':
            table = multiplier_table[NARROW_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'u':
            table = multiplier_table[UNSAFE_TABLE];
            tab_index = strtol(optarg, ((void *)0), 0);
            break;
        case 'a':
            a = strtoul(optarg, ((void *)0), 0);
            break;
        case 'r':
            r = strtoul(optarg, ((void *)0), 0);
            break;
        case 'q': quick = 1;
            break;
        case 'h':
            usage();
            return 0;
        default:
            fprintf(stderr, "Invalid argument.\n");
            usage();
            exit(1);
        }
    if (r < 1 || r > 32)
    {
        fprintf(stderr, "Out-of-range lag value.\n");
        exit(1);
    }
    if (a == 0)
    {
        if (table == ((void *)0))
        {
            fprintf(stderr, "Must choose multiplier.\n");
            exit(1);
        }
        if (tab_index < 0)
            tab_index += table[r].len;
        if ((unsigned int)tab_index >= table[r].len)
        {
            if (table[r].len > 0)
                fprintf(stderr, "Only %d known lag-%d multipliers.\n", table[r].len, r);
            else
                fprintf(stderr, "No known lag-%d multipliers.\n", r);
            exit(1);
        }
        a = table[r].tab[tab_index];
    }
    a_lo = a & 0xff;
    printf("b=256 a=0x%04x r=%d\n", a, r);
    if (255 * a_lo + a - 1 > 0xffff)
    {
        fprintf(stderr, "This multiplier could overflow internal arithmetic.\n");
        exit(1);
    }
    argc -= optind;
    argv += optind;
    test_loop(a, r, quick);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: quick int

variable_types: struct tabptr_t { int len; unsigned int *tab; } *

variable_types: optc int


usage

decompiled_code:
int usage()
{
return puts(
"8bitrand -w <i> -r <r> wide multiply\n"
"8bitrand -n <i> -r <r> narrow multiply\n"
"8bitrand -u <i> -r <r> narrow multiply (unsafe primes)\n"
"8bitrand -a <a> -r <r> user-specified multiply\n"
"\t-{w|n|u} <i> index of known-good multiplier to use\n"
"\t-a <a> multiplier to use\n"
"\t-r <r> generator lag");
}

canonical_decompiled_code:
int func6()
{
return puts(
"8bitrand -w <i> -r <r> wide multiply\n"
"8bitrand -n <i> -r <r> narrow multiply\n"
"8bitrand -u <i> -r <r> narrow multiply (unsafe primes)\n"
"8bitrand -a <a> -r <r> user-specified multiply\n"
"\t-{w|n|u} <i> index of known-good multiplier to use\n"
"\t-a <a> multiplier to use\n"
"\t-r <r> generator lag");
}

original_code:
static void usage(void)
{
    printf("8bitrand -w <i> -r <r>  wide multiply\n"
           "8bitrand -n <i> -r <r>  narrow multiply\n"
           "8bitrand -u <i> -r <r>  narrow multiply (unsafe primes)\n"
           "8bitrand -a <a> -r <r>  user-specified multiply\n"
           "\t-{w|n|u} <i> index of known-good multiplier to use\n"
           "\t-a <a> multiplier to use\n"
           "\t-r <r> generator lag\n");
}

canonical_original_code:
static void usage()
{
    printf("8bitrand -w <i> -r <r>  wide multiply\n"
           "8bitrand -n <i> -r <r>  narrow multiply\n"
           "8bitrand -u <i> -r <r>  narrow multiply (unsafe primes)\n"
           "8bitrand -a <a> -r <r>  user-specified multiply\n"
           "\t-{w|n|u} <i> index of known-good multiplier to use\n"
           "\t-a <a> multiplier to use\n"
           "\t-r <r> generator lag\n");
}