main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
__int64 v4; // rax
__int64 v5; // rax
int v6; // ebx
__int64 v7; // rax
int v8; // ebx
__int64 v9; // rax
int v10; // ebp
int v11; // ebx
__int64 v12; // rax

v3 = (char *)malloc(0x100000uLL);
initstate(0x40A4A42u, v3, 0x100000uLL);
fwrite("// hashrands.h\n// random numbers to use in hashing\n\n", 1uLL, 0x34uLL, _bss_start);
fwrite("#define WKingHash Hash[0]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define BKingHash Hash[1]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define WQueensHash Hash[2]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define BQueensHash Hash[3]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define WRooksHash Hash[4]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define BRooksHash Hash[5]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define WBishopsHash Hash[6]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define BBishopsHash Hash[7]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define WKnightsHash Hash[8]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define BKnightsHash Hash[9]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define WPawnsHash Hash[10]\n", 1uLL, 0x1CuLL, _bss_start);
fwrite("#define BPawnsHash Hash[11]\n", 1uLL, 0x1CuLL, _bss_start);
fputc(10, _bss_start);
fwrite("uint64_t ToMoveHash[2] = {\n", 1uLL, 0x1BuLL, _bss_start);
v4 = random64();
fprintf(_bss_start, "0x%llx,\n", v4);
v5 = random64();
fprintf(_bss_start, "0x%llx,\n", v5);
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
fwrite("uint64_t EPHash[9] = {\n", 1uLL, 0x17uLL, _bss_start);
v6 = 9;
do
{
v7 = random64();
fprintf(_bss_start, "0x%llx,\n", v7);
--v6;
}
while ( v6 );
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
fwrite("uint64_t CastlingHash[16] = {\n", 1uLL, 0x1EuLL, _bss_start);
v8 = 16;
do
{
v9 = random64();
fprintf(_bss_start, "0x%llx,\n", v9);
--v8;
}
while ( v8 );
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
fwrite("uint64_t Hash[12][64] = {\n", 1uLL, 0x1AuLL, _bss_start);
v10 = 12;
do
{
fwrite("{\n", 1uLL, 2uLL, _bss_start);
v11 = 64;
do
{
v12 = random64();
fprintf(_bss_start, "0x%llx,\n", v12);
--v11;
}
while ( v11 );
fwrite("},\n", 1uLL, 3uLL, _bss_start);
--v10;
}
while ( v10 );
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
__int64 v4; // rax
__int64 v5; // rax
int v6; // ebx
__int64 v7; // rax
int v8; // ebx
__int64 v9; // rax
int v10; // ebp
int v11; // ebx
__int64 v12; // rax

v3 = (char *)malloc(0x100000uLL);
initstate(0x40A4A42u, v3, 0x100000uLL);
fwrite("// hashrands.h\n// random numbers to use in hashing\n\n", 1uLL, 0x34uLL, _bss_start);
fwrite("#define WKingHash Hash[0]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define BKingHash Hash[1]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define WQueensHash Hash[2]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define BQueensHash Hash[3]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define WRooksHash Hash[4]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define BRooksHash Hash[5]\n", 1uLL, 0x1BuLL, _bss_start);
fwrite("#define WBishopsHash Hash[6]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define BBishopsHash Hash[7]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define WKnightsHash Hash[8]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define BKnightsHash Hash[9]\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("#define WPawnsHash Hash[10]\n", 1uLL, 0x1CuLL, _bss_start);
fwrite("#define BPawnsHash Hash[11]\n", 1uLL, 0x1CuLL, _bss_start);
fputc(10, _bss_start);
fwrite("uint64_t ToMoveHash[2] = {\n", 1uLL, 0x1BuLL, _bss_start);
v4 = func7();
fprintf(_bss_start, "0x%llx,\n", v4);
v5 = func7();
fprintf(_bss_start, "0x%llx,\n", v5);
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
fwrite("uint64_t EPHash[9] = {\n", 1uLL, 0x17uLL, _bss_start);
v6 = 9;
do
{
v7 = func7();
fprintf(_bss_start, "0x%llx,\n", v7);
--v6;
}
while ( v6 );
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
fwrite("uint64_t CastlingHash[16] = {\n", 1uLL, 0x1EuLL, _bss_start);
v8 = 16;
do
{
v9 = func7();
fprintf(_bss_start, "0x%llx,\n", v9);
--v8;
}
while ( v8 );
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
fwrite("uint64_t Hash[12][64] = {\n", 1uLL, 0x1AuLL, _bss_start);
v10 = 12;
do
{
fwrite("{\n", 1uLL, 2uLL, _bss_start);
v11 = 64;
do
{
v12 = func7();
fprintf(_bss_start, "0x%llx,\n", v12);
--v11;
}
while ( v11 );
fwrite("},\n", 1uLL, 3uLL, _bss_start);
--v10;
}
while ( v10 );
fwrite("};\n\n", 1uLL, 4uLL, _bss_start);
return 0;
}

original_code:
int main(void)
{
    char *states = malloc(1024 * 1024);
    initstate(67783234, states, 1024 * 1024);
    fprintf(stdout, "// hashrands.h\n// random numbers to use in hashing\n\n");
    fprintf(stdout, "#define WKingHash  Hash[0]\n");
    fprintf(stdout, "#define BKingHash  Hash[1]\n");
    fprintf(stdout, "#define WQueensHash    Hash[2]\n");
    fprintf(stdout, "#define BQueensHash    Hash[3]\n");
    fprintf(stdout, "#define WRooksHash Hash[4]\n");
    fprintf(stdout, "#define BRooksHash Hash[5]\n");
    fprintf(stdout, "#define WBishopsHash   Hash[6]\n");
    fprintf(stdout, "#define BBishopsHash   Hash[7]\n");
    fprintf(stdout, "#define WKnightsHash   Hash[8]\n");
    fprintf(stdout, "#define BKnightsHash   Hash[9]\n");
    fprintf(stdout, "#define WPawnsHash Hash[10]\n");
    fprintf(stdout, "#define BPawnsHash Hash[11]\n");
    fprintf(stdout, "\n");
    fprintf(stdout, "uint64_t ToMoveHash[2] = {\n");
    for (int i = 0; i < 2; i++) {
        fprintf(stdout, "0x%llx,\n", random64());
    }
    fprintf(stdout, "};\n\n");
    fprintf(stdout, "uint64_t EPHash[9] = {\n");
    for (int i = 0; i < 9; i++) {
        fprintf(stdout, "0x%llx,\n", random64());
    }
    fprintf(stdout, "};\n\n");
    fprintf(stdout, "uint64_t CastlingHash[16] = {\n");
    for (int i = 0; i < 16; i++) {
        fprintf(stdout, "0x%llx,\n", random64());
    }
    fprintf(stdout, "};\n\n");
    fprintf(stdout, "uint64_t Hash[12][64] = {\n");
    for (int i = 0; i < 12; i++) {
        fprintf(stdout, "{\n");
        for (int j = 0; j < 64; j++) {
            fprintf(stdout, "0x%llx,\n", random64());
        }
        fprintf(stdout, "},\n");
    }
    fprintf(stdout, "};\n\n");
    return (0);
}

canonical_original_code:
int main()
{
    char *states = malloc(1024 * 1024);
    initstate(67783234, states, 1024 * 1024);
    fprintf(stdout, "// hashrands.h\n// random numbers to use in hashing\n\n");
    fprintf(stdout, "#define WKingHash  Hash[0]\n");
    fprintf(stdout, "#define BKingHash  Hash[1]\n");
    fprintf(stdout, "#define WQueensHash    Hash[2]\n");
    fprintf(stdout, "#define BQueensHash    Hash[3]\n");
    fprintf(stdout, "#define WRooksHash Hash[4]\n");
    fprintf(stdout, "#define BRooksHash Hash[5]\n");
    fprintf(stdout, "#define WBishopsHash   Hash[6]\n");
    fprintf(stdout, "#define BBishopsHash   Hash[7]\n");
    fprintf(stdout, "#define WKnightsHash   Hash[8]\n");
    fprintf(stdout, "#define BKnightsHash   Hash[9]\n");
    fprintf(stdout, "#define WPawnsHash Hash[10]\n");
    fprintf(stdout, "#define BPawnsHash Hash[11]\n");
    fprintf(stdout, "\n");
    fprintf(stdout, "uint64_t ToMoveHash[2] = {\n");
    for (int i = 0; i < 2; i++) {
        fprintf(stdout, "0x%llx,\n", random64());
    }
    fprintf(stdout, "};\n\n");
    fprintf(stdout, "uint64_t EPHash[9] = {\n");
    for (int i = 0; i < 9; i++) {
        fprintf(stdout, "0x%llx,\n", random64());
    }
    fprintf(stdout, "};\n\n");
    fprintf(stdout, "uint64_t CastlingHash[16] = {\n");
    for (int i = 0; i < 16; i++) {
        fprintf(stdout, "0x%llx,\n", random64());
    }
    fprintf(stdout, "};\n\n");
    fprintf(stdout, "uint64_t Hash[12][64] = {\n");
    for (int i = 0; i < 12; i++) {
        fprintf(stdout, "{\n");
        for (int j = 0; j < 64; j++) {
            fprintf(stdout, "0x%llx,\n", random64());
        }
        fprintf(stdout, "},\n");
    }
    fprintf(stdout, "};\n\n");
    return (0);
}

variable_types:
states
char *

variable_types: i int

variable_types: j int


repo: namelessjon/librabin

decompiled_code:
void __fastcall rabin_splitter_free(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 360);
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 360);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void rabin_splitter_free(rabin_splitter_t * splitter) {
    if (splitter) {
        if (splitter->buffer) {
            free(splitter->buffer);
            splitter->buffer = ((void *)0);
        }
        free(splitter);
        splitter = ((void *)0);
    }
}

canonical_original_code:
void rabin_splitter_free(struct rabin_splitter_t *splitter) {
    if (splitter) {
        if (splitter->buffer) {
            free(splitter->buffer);
            splitter->buffer = ((void *)0);
        }
        free(splitter);
        splitter = ((void *)0);
    }
}

variable_types: struct rabin_splitter_t { unsigned long long prime; unsigned long window_size; unsigned long min_blk_sz; unsigned long avg_blk_sz; unsigned long max_blk_sz; unsigned long long blk_sz; unsigned long long fingerprint; unsigned long long polynomial_map[256]; struct rabin_node_t { unsigned long long value; struct rabin_node_t *next; } cycle[48]; struct rabin_node_t *curr; unsigned char *buffer; } *

return_type: void

user_defined_types: struct rabin_splitter_t { unsigned long long prime; unsigned long window_size; unsigned long min_blk_sz; unsigned long avg_blk_sz; unsigned long max_blk_sz; unsigned long long blk_sz; unsigned long long fingerprint; unsigned long long polynomial_map[256]; struct rabin_node_t cycle[48]; struct rabin_node_t *curr; unsigned char *buffer; }


original_code:
int rabin_split_file(rabin_splitter_t * rsp,
                     int fileno,
                     rsp_chunk_callback cb,
                     void *userdata) {
    int ch;
    int i = 0, nread = 0;
    unsigned char input_buffer[(32768)];
    if ((!rsp)||(!cb))
        return 1;
    while ((nread = read(fileno, input_buffer, (32768)))) {
        for (i = 0; i < nread; i++) {
            ch = input_buffer[i];
            rsp->buffer[rsp->blk_sz] = ch;
            rsp->fingerprint *= rsp->prime;
            rsp->fingerprint += ch;
            rsp->fingerprint -= rsp->polynomial_map[rsp->curr->value];
            rsp->curr->value = ch;
            rsp->curr = rsp->curr->next;
            rsp->blk_sz++;
            if ((rsp->blk_sz > rsp->min_blk_sz)) {
                if (((rsp->fingerprint & rsp->avg_blk_sz) == 1) || (rsp->blk_sz >= rsp->max_blk_sz)) {
                    (*cb)(rsp->blk_sz, rsp->buffer, userdata);
                    rsp->blk_sz = 0;
                }
            }
        }
    }
    if (rsp->blk_sz != 0)
        (*cb)(rsp->blk_sz, rsp->buffer, userdata);
    return 0;
}

canonical_original_code:
int rabin_split_file(struct rabin_splitter_t *rsp, int fileno, void (*cb)(unsigned long long blk_sz, unsigned char *chunk, void *userdata), void *userdata) {
    int ch;
    int i = 0; int nread = 0;
    unsigned char input_buffer[-1];
    if ((!rsp)||(!cb))
        return 1;
    while ((nread = read(fileno, input_buffer, (32768)))) {
        for (i = 0; i < nread; i++) {
            ch = input_buffer[i];
            rsp->buffer[rsp->blk_sz] = ch;
            rsp->fingerprint *= rsp->prime;
            rsp->fingerprint += ch;
            rsp->fingerprint -= rsp->polynomial_map[rsp->curr->value];
            rsp->curr->value = ch;
            rsp->curr = rsp->curr->next;
            rsp->blk_sz++;
            if ((rsp->blk_sz > rsp->min_blk_sz)) {
                if (((rsp->fingerprint & rsp->avg_blk_sz) == 1) || (rsp->blk_sz >= rsp->max_blk_sz)) {
                    (*cb)(rsp->blk_sz, rsp->buffer, userdata);
                    rsp->blk_sz = 0;
                }
            }
        }
    }
    if (rsp->blk_sz != 0)
        (*cb)(rsp->blk_sz, rsp->buffer, userdata);
    return 0;
}

variable_types: fileno int

variable_types: void (*)(unsigned long long blk_sz, unsigned char *chunk, void *userdata)

variable_types:
userdata
void *

variable_types: ch int

variable_types: nread int

return_type: int

user_defined_types: struct rabin_node_t { unsigned long long value; struct rabin_node_t *next; }


alsaOutClose

repo: nanase/EasyAlsa

decompiled_code:
__int64 alsaOutClose()
{
return snd_pcm_close();
}

canonical_decompiled_code:
__int64 func7()
{
return snd_pcm_close();
}

original_code:
int32_t alsaOutClose(void *handle) {
  return snd_pcm_close(handle);
}

canonical_original_code:
int alsaOutClose(void *handle) {
  return snd_pcm_close(handle);
}

variable_types:
handle
void *


alsaOutSetParams

decompiled_code:
__int64 alsaOutSetParams()
{
return snd_pcm_set_params();
}

canonical_decompiled_code:
__int64 func8()
{
return snd_pcm_set_params();
}

original_code:
int32_t alsaOutSetParams(void *handle,
        alsaPcmFormat_t format,
        uint32_t channels,
        uint32_t rate,
        uint32_t latency) {
  return snd_pcm_set_params(handle,
          (snd_pcm_format_t) format,
          SND_PCM_ACCESS_RW_INTERLEAVED,
          channels,
          rate,
          1,
          latency);
}

canonical_original_code:
int alsaOutSetParams(void *handle, enum _alsaPcmFormat_t format, unsigned int channels, unsigned int rate, unsigned int latency) {
  return snd_pcm_set_params(handle,
          (enum _snd_pcm_format) format,
          SND_PCM_ACCESS_RW_INTERLEAVED,
          channels,
          rate,
          1,
          latency);
}

variable_types: enum _alsaPcmFormat_t { ALSA_PCM_FORMAT_UNKNOWN=-1, ALSA_PCM_FORMAT_S8=0, ALSA_PCM_FORMAT_U8=1, ALSA_PCM_FORMAT_S16_LE=2, ALSA_PCM_FORMAT_S16_BE=3, ALSA_PCM_FORMAT_U16_LE=4, ALSA_PCM_FORMAT_U16_BE=5, ALSA_PCM_FORMAT_S24_LE=6, ALSA_PCM_FORMAT_S24_BE=7, ALSA_PCM_FORMAT_U24_LE=8, ALSA_PCM_FORMAT_U24_BE=9, ALSA_PCM_FORMAT_S32_LE=10, ALSA_PCM_FORMAT_S32_BE=11, ALSA_PCM_FORMAT_U32_LE=12, ALSA_PCM_FORMAT_U32_BE=13, ALSA_PCM_FORMAT_FLOAT_LE=14, ALSA_PCM_FORMAT_FLOAT_BE=15, ALSA_PCM_FORMAT_FLOAT64_LE=16, ALSA_PCM_FORMAT_FLOAT64_BE=17, ALSA_PCM_FORMAT_IEC958_SUBFRAME_LE=18, ALSA_PCM_FORMAT_IEC958_SUBFRAME_BE=19, ALSA_PCM_FORMAT_MU_LAW=20, ALSA_PCM_FORMAT_A_LAW=21, ALSA_PCM_FORMAT_IMA_ADPCM=22, ALSA_PCM_FORMAT_MPEG=23, ALSA_PCM_FORMAT_GSM=24, ALSA_PCM_FORMAT_SPECIAL=31, ALSA_PCM_FORMAT_S24_3LE=32, ALSA_PCM_FORMAT_S24_3BE=33, ALSA_PCM_FORMAT_U24_3LE=34, ALSA_PCM_FORMAT_U24_3BE=35, ALSA_PCM_FORMAT_S20_3LE=36, ALSA_PCM_FORMAT_S20_3BE=37, ALSA_PCM_FORMAT_U20_3LE=38, ALSA_PCM_FORMAT_U20_3BE=39, ALSA_PCM_FORMAT_S18_3LE=40, ALSA_PCM_FORMAT_S18_3BE=41, ALSA_PCM_FORMAT_U18_3LE=42, ALSA_PCM_FORMAT_U18_3BE=43, ALSA_PCM_FORMAT_G723_24=44, ALSA_PCM_FORMAT_G723_24_1B=45, ALSA_PCM_FORMAT_G723_40=46, ALSA_PCM_FORMAT_G723_40_1B=47, ALSA_PCM_FORMAT_DSD_U8=48, ALSA_PCM_FORMAT_DSD_U16_LE=49, ALSA_PCM_FORMAT_LAST=expr, ALSA_PCM_FORMAT_S16=expr, ALSA_PCM_FORMAT_U16=expr, ALSA_PCM_FORMAT_S24=expr, ALSA_PCM_FORMAT_U24=expr, ALSA_PCM_FORMAT_S32=expr, ALSA_PCM_FORMAT_U32=expr, ALSA_PCM_FORMAT_FLOAT=expr, ALSA_PCM_FORMAT_FLOAT64=expr, ALSA_PCM_FORMAT_IEC958_SUBFRAME=expr }

variable_types:
channels
unsigned int

variable_types:
rate
unsigned int

variable_types:
latency
unsigned int

user_defined_types: enum _snd_pcm_format { SND_PCM_FORMAT_UNKNOWN=-1, SND_PCM_FORMAT_S8=0, SND_PCM_FORMAT_U8=1, SND_PCM_FORMAT_S16_LE=2, SND_PCM_FORMAT_S16_BE=3, SND_PCM_FORMAT_U16_LE=4, SND_PCM_FORMAT_U16_BE=5, SND_PCM_FORMAT_S24_LE=6, SND_PCM_FORMAT_S24_BE=7, SND_PCM_FORMAT_U24_LE=8, SND_PCM_FORMAT_U24_BE=9, SND_PCM_FORMAT_S32_LE=10, SND_PCM_FORMAT_S32_BE=11, SND_PCM_FORMAT_U32_LE=12, SND_PCM_FORMAT_U32_BE=13, SND_PCM_FORMAT_FLOAT_LE=14, SND_PCM_FORMAT_FLOAT_BE=15, SND_PCM_FORMAT_FLOAT64_LE=16, SND_PCM_FORMAT_FLOAT64_BE=17, SND_PCM_FORMAT_IEC958_SUBFRAME_LE=18, SND_PCM_FORMAT_IEC958_SUBFRAME_BE=19, SND_PCM_FORMAT_MU_LAW=20, SND_PCM_FORMAT_A_LAW=21, SND_PCM_FORMAT_IMA_ADPCM=22, SND_PCM_FORMAT_MPEG=23, SND_PCM_FORMAT_GSM=24, SND_PCM_FORMAT_S20_LE=25, SND_PCM_FORMAT_S20_BE=26, SND_PCM_FORMAT_U20_LE=27, SND_PCM_FORMAT_U20_BE=28, SND_PCM_FORMAT_SPECIAL=31, SND_PCM_FORMAT_S24_3LE=32, SND_PCM_FORMAT_S24_3BE=33, SND_PCM_FORMAT_U24_3LE=34, SND_PCM_FORMAT_U24_3BE=35, SND_PCM_FORMAT_S20_3LE=36, SND_PCM_FORMAT_S20_3BE=37, SND_PCM_FORMAT_U20_3LE=38, SND_PCM_FORMAT_U20_3BE=39, SND_PCM_FORMAT_S18_3LE=40, SND_PCM_FORMAT_S18_3BE=41, SND_PCM_FORMAT_U18_3LE=42, SND_PCM_FORMAT_U18_3BE=43, SND_PCM_FORMAT_G723_24=44, SND_PCM_FORMAT_G723_24_1B=45, SND_PCM_FORMAT_G723_40=46, SND_PCM_FORMAT_G723_40_1B=47, SND_PCM_FORMAT_DSD_U8=48, SND_PCM_FORMAT_DSD_U16_LE=49, SND_PCM_FORMAT_DSD_U32_LE=50, SND_PCM_FORMAT_DSD_U16_BE=51, SND_PCM_FORMAT_DSD_U32_BE=52, SND_PCM_FORMAT_LAST=expr, SND_PCM_FORMAT_S16=expr, SND_PCM_FORMAT_U16=expr, SND_PCM_FORMAT_S24=expr, SND_PCM_FORMAT_U24=expr, SND_PCM_FORMAT_S32=expr, SND_PCM_FORMAT_U32=expr, SND_PCM_FORMAT_FLOAT=expr, SND_PCM_FORMAT_FLOAT64=expr, SND_PCM_FORMAT_IEC958_SUBFRAME=expr, SND_PCM_FORMAT_S20=expr, SND_PCM_FORMAT_U20=expr }


alsaOutWrite

decompiled_code:
__int64 alsaOutWrite()
{
return snd_pcm_writei();
}

canonical_decompiled_code:
__int64 func9()
{
return snd_pcm_writei();
}

original_code:
int32_t alsaOutWrite(void *handle, const void *buffer, uint32_t size) {
  return snd_pcm_writei(handle, buffer, size);
}

canonical_original_code:
int alsaOutWrite(void *handle, void *buffer, unsigned int size) {
  return snd_pcm_writei(handle, buffer, size);
}

variable_types:
buffer
void *

variable_types:
size
unsigned int


alsaOutRecover

decompiled_code:
__int64 alsaOutRecover()
{
return snd_pcm_recover();
}

canonical_decompiled_code:
__int64 func10()
{
return snd_pcm_recover();
}

original_code:
int32_t alsaOutRecover(void *handle, int32_t error) {
  return snd_pcm_recover(handle, error, 1);
}

canonical_original_code:
int alsaOutRecover(void *handle, int error) {
  return snd_pcm_recover(handle, error, 1);
}

variable_types: error int


alsaOutRecoverDebug

decompiled_code:
__int64 alsaOutRecoverDebug()
{
return snd_pcm_recover();
}

canonical_decompiled_code:
__int64 func11()
{
return snd_pcm_recover();
}

original_code:
int32_t alsaOutRecoverDebug(void *handle, int32_t error, int32_t silent) {
  return snd_pcm_recover(handle, error, silent);
}

canonical_original_code:
int alsaOutRecoverDebug(void *handle, int error, int silent) {
  return snd_pcm_recover(handle, error, silent);
}

variable_types: silent int


alsaOutStart

decompiled_code:
__int64 alsaOutStart()
{
return snd_pcm_start();
}

canonical_decompiled_code:
__int64 func12()
{
return snd_pcm_start();
}

original_code:
int32_t alsaOutStart(void *handle) {
  return snd_pcm_start(handle);
}

canonical_original_code:
int alsaOutStart(void *handle) {
  return snd_pcm_start(handle);
}


alsaOutPause

decompiled_code:
__int64 alsaOutPause()
{
return snd_pcm_pause();
}

canonical_decompiled_code:
__int64 func13()
{
return snd_pcm_pause();
}

original_code:
int32_t alsaOutPause(void *handle, int32_t enable) {
  return snd_pcm_pause(handle, enable);
}

canonical_original_code:
int alsaOutPause(void *handle, int enable) {
  return snd_pcm_pause(handle, enable);
}

variable_types: enable int


alsaOutResume

decompiled_code:
__int64 alsaOutResume()
{
return snd_pcm_resume();
}

canonical_decompiled_code:
__int64 func14()
{
return snd_pcm_resume();
}

original_code:
int32_t alsaOutResume(void *handle) {
  return snd_pcm_resume(handle);
}

canonical_original_code:
int alsaOutResume(void *handle) {
  return snd_pcm_resume(handle);
}


alsaOutDrop

decompiled_code:
__int64 alsaOutDrop()
{
return snd_pcm_drop();
}

canonical_decompiled_code:
__int64 func15()
{
return snd_pcm_drop();
}

original_code:
int32_t alsaOutDrop(void *handle) {
  return snd_pcm_drop(handle);
}

canonical_original_code:
int alsaOutDrop(void *handle) {
  return snd_pcm_drop(handle);
}


alsaOutDrain

decompiled_code:
__int64 alsaOutDrain()
{
return snd_pcm_drain();
}

canonical_decompiled_code:
__int64 func16()
{
return snd_pcm_drain();
}

original_code:
int32_t alsaOutDrain(void *handle) {
  return snd_pcm_drain(handle);
}

canonical_original_code:
int alsaOutDrain(void *handle) {
  return snd_pcm_drain(handle);
}


alsaOutReset

decompiled_code:
__int64 alsaOutReset()
{
return snd_pcm_reset();
}

canonical_decompiled_code:
__int64 func17()
{
return snd_pcm_reset();
}

original_code:
int32_t alsaOutReset(void *handle) {
  return snd_pcm_reset(handle);
}

canonical_original_code:
int alsaOutReset(void *handle) {
  return snd_pcm_reset(handle);
}


alsaOutWait

decompiled_code:
__int64 alsaOutWait()
{
return snd_pcm_wait();
}

canonical_decompiled_code:
__int64 func19()
{
return snd_pcm_wait();
}

original_code:
int32_t alsaOutWait(void *handle, int32_t timeout) {
  return snd_pcm_wait(handle, timeout);
}

canonical_original_code:
int alsaOutWait(void *handle, int timeout) {
  return snd_pcm_wait(handle, timeout);
}

variable_types: timeout int


alsaErrorString

decompiled_code:
__int64 alsaErrorString()
{
return snd_strerror();
}

canonical_decompiled_code:
__int64 func20()
{
return snd_strerror();
}

original_code:
const char *alsaErrorString(int32_t errornum) {
  return snd_strerror(errornum);
}

canonical_original_code:
char *alsaErrorString(int errornum) {
  return snd_strerror(errornum);
}

variable_types: errornum int

return_type: char *


repo: nanley/glawn

decompiled_code:
__int64 __fastcall curl_callback(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return g_strlcpy(a4, a1, 160LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return g_strlcpy(a4, a1, 160LL);
}

original_code:
size_t curl_callback (void *buffer, size_t size, size_t nmemb, void *userp)
{
 return g_strlcpy ((char *)userp, (char *)buffer, 160);
}

canonical_original_code:
unsigned long curl_callback(void *buffer, unsigned long size, unsigned long nmemb, void *userp)
{
 return g_strlcpy ((char *)userp, (char *)buffer, 160);
}

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
userp
void *

return_type: unsigned long


decompiled_code:
__int64 quit_glawn()
{
save_settings();
curl_easy_cleanup(curl);
g_free(buffer);
g_mutex_unlock(GTK_Mutex);
g_mutex_free(GTK_Mutex);
return gtk_main_quit();
}

canonical_decompiled_code:
__int64 func3()
{
save_settings();
curl_easy_cleanup(curl);
g_free(buffer);
g_mutex_unlock(GTK_Mutex);
g_mutex_free(GTK_Mutex);
return gtk_main_quit();
}

original_code:
void quit_glawn ()
{
 save_settings();
 curl_easy_cleanup (curl);
 g_free (buffer);
 g_mutex_unlock(GTK_Mutex);
 g_mutex_free(GTK_Mutex);
 gtk_main_quit ();
}

canonical_original_code:
void quit_glawn()
{
 save_settings();
 curl_easy_cleanup (curl);
 g_free (buffer);
 g_mutex_unlock(GTK_Mutex);
 g_mutex_free(GTK_Mutex);
 gtk_main_quit ();
}


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

if ( GTK_Mutex )
{
g_assertion_message_expr(0LL, "callbacks.c", 68LL, "init_mutex", "GTK_Mutex == NULL");
result = init_check_status();
}
else
{
result = g_mutex_new();
GTK_Mutex = result;
}
return result;
}

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

if ( GTK_Mutex )
{
g_assertion_message_expr(0LL, "callbacks.c", 68LL, "init_mutex", "GTK_Mutex == NULL");
result = func5();
}
else
{
result = g_mutex_new();
GTK_Mutex = result;
}
return result;
}

original_code:
void init_mutex() {
 do { if (GTK_Mutex == ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "callbacks.c", 68, ((const char*) (__func__)), "GTK_Mutex == NULL"); } while (0);
 GTK_Mutex = g_mutex_new();
}

canonical_original_code:
void init_mutex() {
 do { if (GTK_Mutex == ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "callbacks.c", 68, ((char *) (__func__)), "GTK_Mutex == NULL"); } while (0);
 GTK_Mutex = g_mutex_new();
}


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

v0 = g_mutex_trylock(GTK_Mutex);
result = 1LL;
if ( v0 )
{
update_gui(4LL);
result = 0LL;
}
return result;
}

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

v0 = g_mutex_trylock(GTK_Mutex);
result = 1LL;
if ( v0 )
{
update_gui(4LL);
result = 0LL;
}
return result;
}

original_code:
int init_check_status() {
 if (g_mutex_trylock(GTK_Mutex)) {
  update_gui (CHECK_STAT_END);
  return (0);
 }
 return (!(0));
}


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

settings = g_key_file_new();
result = g_key_file_load_from_file(settings, "./config/settings.ini", 1LL, 0LL);
if ( !(_DWORD)result )
{
fprintf(stderr, "Can't find settings file: %s\n", "./config/settings.ini");
exit(1);
}
return result;
}

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

settings = g_key_file_new();
result = g_key_file_load_from_file(settings, "./config/settings.ini", 1LL, 0LL);
if ( !(_DWORD)result )
{
fprintf(stderr, "Can't find settings file: %s\n", "./config/settings.ini");
exit(1);
}
return result;
}

original_code:
void load_settings ()
{
 settings = g_key_file_new();
 if (!g_key_file_load_from_file(settings, "./config/settings.ini", G_KEY_FILE_KEEP_COMMENTS, ((void *)0))) {
  fprintf(stderr, "Can't find settings file: %s\n", "./config/settings.ini");
  exit(1);
 }
}

canonical_original_code:
void load_settings()
{
 settings = g_key_file_new();
 if (!g_key_file_load_from_file(settings, "./config/settings.ini", G_KEY_FILE_KEEP_COMMENTS, ((void *)0))) {
  fprintf(stderr, "Can't find settings file: %s\n", "./config/settings.ini");
  exit(1);
 }
}


decompiled_code:
__int64 save_settings()
{
__int64 v0; // rax
__int64 v1; // rax
unsigned int v2; // eax
__int64 v3; // rax

v0 = gtk_toggle_button_get_type();
v1 = g_type_check_instance_cast(data[4], v0);
v2 = gtk_toggle_button_get_active(v1);
g_key_file_set_integer(settings, "config", "current", v2);
v3 = g_key_file_to_data(settings, 0LL, 0LL);
g_file_set_contents("./config/settings.ini", v3, -1LL, 0LL);
return g_key_file_free(settings);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
__int64 v1; // rax
unsigned int v2; // eax
__int64 v3; // rax

v0 = gtk_toggle_button_get_type();
v1 = g_type_check_instance_cast(data[4], v0);
v2 = gtk_toggle_button_get_active(v1);
g_key_file_set_integer(settings, "config", "current", v2);
v3 = g_key_file_to_data(settings, 0LL, 0LL);
g_file_set_contents("./config/settings.ini", v3, -1LL, 0LL);
return g_key_file_free(settings);
}

original_code:
void save_settings ()
{
 int index = gtk_toggle_button_get_active (((((GtkToggleButton*) g_type_check_instance_cast ((GTypeInstance*) ((data.locCBox)), ((gtk_toggle_button_get_type ())))))));
 g_key_file_set_integer(settings, "config", "current", index);
 gchar *settings_data = g_key_file_to_data(settings, ((void *)0), ((void *)0));
 g_file_set_contents ("./config/settings.ini", settings_data, -1, ((void *)0));
 g_key_file_free(settings);
}

canonical_original_code:
void save_settings()
{
 int index = gtk_toggle_button_get_active (((((GtkToggleButton*) g_type_check_instance_cast ((GTypeInstance*) ((data.locCBox)), ((gtk_toggle_button_get_type ())))))));
 g_key_file_set_integer(settings, "config", "current", index);
 char *settings_data = g_key_file_to_data(settings, ((void *)0), ((void *)0));
 g_file_set_contents ("./config/settings.ini", settings_data, -1, ((void *)0));
 g_key_file_free(settings);
}

variable_types: index int


decompiled_code:
char *get_url()
{
__int64 v0; // rax
__int64 v1; // rax

v0 = gtk_toggle_button_get_type();
v1 = g_type_check_instance_cast(data[4], v0);
return locs_0[(int)gtk_toggle_button_get_active(v1)];
}

canonical_decompiled_code:
char *func2()
{
__int64 v0; // rax
__int64 v1; // rax

v0 = gtk_toggle_button_get_type();
v1 = g_type_check_instance_cast(data[4], v0);
return locs_0[(int)gtk_toggle_button_get_active(v1)];
}

original_code:
gchar *get_url ()
{
 static gchar *locs[] = {
  "https://auth.lawn.gatech.edu/",
  "https://mower.georgiatech-metz.fr/"
 };
 int index = gtk_toggle_button_get_active (((((GtkToggleButton*) g_type_check_instance_cast ((GTypeInstance*) ((data.locCBox)), ((gtk_toggle_button_get_type ())))))));
 return locs[index];
}

canonical_original_code:
char *get_url()
{
 static char *locs[] = {
  "https://auth.lawn.gatech.edu/",
  "https://mower.georgiatech-metz.fr/"
 };
 int index = gtk_toggle_button_get_active (((((GtkToggleButton*) g_type_check_instance_cast ((GTypeInstance*) ((data.locCBox)), ((gtk_toggle_button_get_type ())))))));
 return locs[index];
}

variable_types:
locs
char *[]


decompiled_code:
__int64 get_url_index()
{
return g_key_file_get_integer(settings, "config", "current", 0LL);
}

canonical_decompiled_code:
__int64 func3()
{
return g_key_file_get_integer(settings, "config", "current", 0LL);
}

original_code:
int get_url_index ()
{
 return g_key_file_get_integer(settings, "config", "current", ((void *)0));
}

canonical_original_code:
int get_url_index()
{
 return g_key_file_get_integer(settings, "config", "current", ((void *)0));
}


decompiled_code:
__int64 __fastcall update_cmd(const char *a1)
{
__int64 result; // rax
const char *v2; // rax

if ( curl_return )
{
v2 = (const char *)curl_easy_strerror();
g_printf("libcurl output: %s\n", v2);
result = g_printf("%s: No reply received\n\n", a1);
}
else
{
g_printf("libcurl output: :)\n");
result = g_printf("%s: %s\n\n", a1, buffer);
}
return result;
}

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

if ( curl_return )
{
v2 = (const char *)curl_easy_strerror();
g_printf("libcurl output: %s\n", v2);
result = g_printf("%s: No reply received\n\n", a1);
}
else
{
g_printf("libcurl output: :)\n");
result = g_printf("%s: %s\n\n", a1, buffer);
}
return result;
}

original_code:
void update_cmd (char *custom)
{
 if (curl_return == CURLE_OK) {
  g_printf ("libcurl output: :)\n");
  g_printf ("%s: %s\n\n", custom, buffer);
 } else {
  g_printf ("libcurl output: %s\n", curl_easy_strerror (curl_return));
  g_printf ("%s: No reply received\n\n", custom);
 }
}

canonical_original_code:
void update_cmd(char *custom)
{
 if (curl_return == CURLE_OK) {
  g_printf ("libcurl output: :)\n");
  g_printf ("%s: %s\n\n", custom, buffer);
 } else {
  g_printf ("libcurl output: %s\n", curl_easy_strerror (curl_return));
  g_printf ("%s: No reply received\n\n", custom);
 }
}

variable_types:
custom
char *


repo: nanoant/mjpeg

variable_types:
h
unsigned int

variable_types: version int


decompiled_code:
__int64 __fastcall mp3samplerate(unsigned int a1)
{
int v1; // edx
int v2; // ecx

v1 = (a1 >> 19) & 3;
v2 = 0;
if ( v1 != 3 )
v2 = (v1 != 2) + 1;
return (unsigned int)samplerates[3 * ((a1 >> 10) & 3) + v2];
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
int v1; // edx
int v2; // ecx

v1 = (a1 >> 19) & 3;
v2 = 0;
if ( v1 != 3 )
v2 = (v1 != 2) + 1;
return (unsigned int)samplerates[3 * ((a1 >> 10) & 3) + v2];
}

original_code:
int mp3samplerate(mp3header_t h) {
 int index = 2;
 int version = (((h) & 0x180000) >> 19);
 if(version == 3) {
  index = 0;
 } else if(version == 2) {
  index = 1;
 }
 return samplerates[index + (((h) & 0xC00) >> 10) * 3];
}

canonical_original_code:
int mp3samplerate(unsigned int h) {
 int index = 2;
 int version = (((h) & 0x180000) >> 19);
 if(version == 3) {
  index = 0;
 } else if(version == 2) {
  index = 1;
 }
 return samplerates[index + (((h) & 0xC00) >> 10) * 3];
}


decompiled_code:
__int64 __fastcall mp3framesize(unsigned int a1)
{
int v1; // ebp
__int64 result; // rax

v1 = mp3bitrate(a1);
if ( ((a1 ^ 0x60000) & 0x60000) != 0 )
result = ((a1 >> 9) & 1) + 144000 * v1 / (int)mp3samplerate(a1);
else
result = 4 * (((a1 >> 9) & 1) + 12000 * v1 / (int)mp3samplerate(a1));
return result;
}

canonical_original_code:
unsigned long mp3framesize(unsigned int h) {
 if((((h) & 0x60000) >> 17) == 3) {
  return (12000 * mp3bitrate(h) / mp3samplerate(h) + (((h) & 0x200) >> 9)) * 4;
 }
 return 144000 * mp3bitrate(h) / mp3samplerate(h) + (((h) & 0x200) >> 9);
}


decompiled_code:
double __fastcall mp3framelength(unsigned int a1)
{
return 1152.0 / (double)(int)mp3samplerate(a1);
}

canonical_decompiled_code:
double __fastcall func5(unsigned int a1)
{
return 1152.0 / (double)(int)func3(a1);
}

original_code:
double mp3framelength(mp3header_t h) {
 return 1152.0 / (double)mp3samplerate(h);
}

canonical_original_code:
double mp3framelength(unsigned int h) {
 return 1152.0 / (double)mp3samplerate(h);
}

return_type: double


fourcc

decompiled_code:
char *__fastcall fourcc(int a1)
{
int v1; // eax
__int64 v2; // rcx

v1 = (rot_1 + 1) % 8;
v2 = 5LL * v1;
byte_2C4[v2] = 0;
*(int *)((char *)&sfcc_0 + v2) = a1;
rot_1 = v1 + 1;
return (char *)&sfcc_0 + v2;
}

canonical_decompiled_code:
char *__fastcall func0(int a1)
{
int v1; // eax
__int64 v2; // rcx

v1 = (rot_1 + 1) % 8;
v2 = 5LL * v1;
byte_2C4[v2] = 0;
*(int *)((char *)&sfcc_0 + v2) = a1;
rot_1 = v1 + 1;
return (char *)&sfcc_0 + v2;
}

original_code:
const char *fourcc(FOURCC fcc) {
 static char sfcc[8][5];
 static int rot = -1;
 rot = (rot + 1) % 8;
 sfcc[rot][4] = 0;
 *(FOURCC *)sfcc[rot] = fcc;
 return sfcc[rot++];
}

canonical_original_code:
char *fourcc(unsigned int fcc) {
 static char sfcc[8][5];
 static int rot = -1;
 rot = (rot + 1) % 8;
 sfcc[rot][4] = 0;
 *(unsigned int *)sfcc[rot] = fcc;
 return sfcc[rot++];
}

variable_types:
fcc
unsigned int

variable_types:
sfcc
char [8][5]

variable_types: rot int


main

canonical_name: main

repo: nanocad-lab/vipzone-memallocator

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
__int64 v6; // rbp
char v7; // al
char v8; // al
char v9; // al
int v10; // er15
__int64 v11; // rbx
unsigned __int64 v12; // rax
unsigned __int64 v13; // r13
unsigned __int64 i; // rbp
void *v15; // rax
double v16; // xmm0_8
_QWORD *v17; // r13
_QWORD *v18; // r14
__int64 v19; // r13
int v20; // eax
__int64 v21; // r13
__int64 v22; // r14
__int64 v23; // rax
double v24; // xmm0_8
__int64 v25; // r13
__int64 v26; // r14
__int64 v27; // rax
double v28; // xmm0_8
double v29; // xmm0_8
double v30; // xmm0_8
__int64 j; // r14
_QWORD *v32; // rcx
__int64 k; // rax
_QWORD *v34; // rcx
__int64 m; // rax
_QWORD *v36; // rsi
__int64 v37; // rcx
__int64 l; // rdi
__int64 v39; // rax
__int64 n; // rcx
__int64 ii; // rax
int jj; // er13
__int64 kk; // r14
__int64 v44; // rax
__int64 v45; // rdx
__int64 v46; // rax
__int64 v47; // rcx
int v48; // edx
__int64 v49; // rax
void **v50; // r12
void **v51; // rbp
__int64 ll; // r12
int v53; // [rsp+8h] [rbp-50h]
int v54; // [rsp+Ch] [rbp-4Ch]
int seconds; // [rsp+10h] [rbp-48h]
int v56; // [rsp+14h] [rbp-44h]

v3 = time(0LL);
srand(v3);
if ( argc == 7 )
{
v6 = atol(argv[1]);
printf("will alloc = %lu MB\n", v6);
seconds = atol(argv[2]);
if ( seconds < 0 )
{
fwrite("Sleep time was < 0s, setting to 0s.\n", 1uLL, 0x24uLL, stderr);
seconds = 0;
}
printf("sleep time = %d s\n", (unsigned int)seconds);
v7 = *argv[3];
switch ( v7 )
{
case 'v':
puts("allocator = vip_mmap");
v4 = 3;
break;
case 'm':
puts("allocator = mmap");
v4 = 1;
break;
case 'M':
puts("allocator = malloc");
v4 = 0;
break;
case 'V':
puts("allocator = vip_malloc");
v4 = 2;
break;
default:
fwrite("Bad allocator choice\n", 1uLL, 0x15uLL, stderr);
return 1;
}
v8 = *argv[4];
switch ( v8 )
{
case 's':
puts("access pattern = staggered");
v54 = 0;
v53 = 1;
break;
case 'r':
puts("access pattern = random");
printf("RAND_MAX = %d\n", 0x7FFFFFFFLL);
v54 = 1;
v53 = 0;
break;
case 'n':
puts("access pattern = sequential");
v54 = 0;
v53 = 0;
break;
default:
fwrite("Bad access pattern flag\n", 1uLL, 0x18uLL, stderr);
return 1;
}
v9 = *argv[5];
if ( v9 == 119 )
{
puts("access mode = write");
v10 = 1;
}
else
{
if ( v9 != 114 )
{
fwrite("Bad write/read input\n", 1uLL, 0x15uLL, stderr);
return 1;
}
puts("access mode = read");
v10 = 0;
}
v56 = atoi(argv[6]);
if ( v56 <= 0 )
{
fwrite("Number of iterations was < 1, setting to 1\n", 1uLL, 0x2BuLL, stderr);
v56 = 1;
}
printf("num iterations = %d\n", (unsigned int)v56);
puts("\n==============================\n");
switch ( v4 )
{
case 2:
puts("Getting memory pointer array using vip_malloc with vip_flags READ/HI...");
LODWORD(v18) = vip_malloc(0x2000000LL, 32LL);
v11 = (int)v18;
if ( !(_DWORD)v18 )
{
puts("Error: Could not allocate page array using vip_malloc (READ/HI). Terminating.");
perror("Failure reason");
return 1;
}
printf(
"sizeof(val) == %lu\nsizeof(page_array) == %lu\nsizeof(*(page_array)) == %lu\nsizeof(**page_array) == %lu\n",
8LL,
8LL,
8LL,
8LL);
printf("PAGE_SIZE == %lu\nwordsPerPage == %lu\n", 4096LL, 512LL);
puts("\n==============================\n");
puts("Hogging memory using vip_malloc...");
v19 = (v6 << 8) & 0xFFFFFFFFFFFFFLL;
v18 = (_QWORD *)(int)v18;
i = 0LL;
while ( v19 != i )
{
v20 = vip_malloc(4096LL, 32LL);
*v18 = v20;
if ( !v20 )
{
if ( (i & 0x8000000000000000LL) != 0LL )
v29 = (double)(int)(i & 1 | (i >> 1)) + (double)(int)(i & 1 | (i >> 1));
else
v29 = (double)(int)i;
printf(
"Error: Failed to vip_malloc page number %lu, at %0.2f MB.\n",
i,
v29 * 4096.0 * 0.00000095367431640625);
perror("Failure reason");
goto LABEL_28;
}
++i;
++v18;
if ( i == 0x400000 )
goto LABEL_28;
}
break;
case 3:
puts("Getting memory pointer array using vip_mmap with vip_flags READ/HI...");
v21 = syscall(312LL, 0LL, 0x2000000LL, 35LL, 34LL, 0xFFFFFFFFLL, 0LL);
v11 = v21;
if ( v21 == -1 )
{
puts("Error: Could not allocate page array using vip_mmap (READ/HI). Terminating.");
perror("Failure reason");
return 1;
}
printf(
"sizeof(val) == %lu\nsizeof(page_array) == %lu\nsizeof(*(page_array)) == %lu\nsizeof(**page_array) == %lu\n",
8LL,
8LL,
8LL,
8LL);
printf("PAGE_SIZE == %lu\nwordsPerPage == %lu\n", 4096LL, 512LL);
puts("\n==============================\n");
puts("Hogging memory using vip_mmap with flags WRITE/HI...");
v22 = (v6 << 8) & 0xFFFFFFFFFFFFFLL;
for ( i = 0LL; i != 0x400000; ++i )
{
if ( v22 == i )
break;
v23 = syscall(312LL, 0LL, 4096LL, 51LL, 34LL, 0xFFFFFFFFLL, 0LL);
*(_QWORD *)(v21 + 8 * i) = v23;
if ( v23 == -1 )
break;
}
if ( *(_QWORD *)(v21 + 8 * i) == -1LL )
{
if ( (i & 0x8000000000000000LL) != 0LL )
v24 = (double)(int)(i & 1 | (i >> 1)) + (double)(int)(i & 1 | (i >> 1));
else
v24 = (double)(int)i;
printf("Error: Failed to vip_mmap page number %lu, at %0.2f MB.\n", i, v24 * 4096.0 * 0.00000095367431640625);
perror("Failure reason");
}
break;
case 1:
puts("Getting memory pointer array using mmap...");
v25 = syscall(9LL, 0LL, 0x2000000LL, 3LL, 34LL, 0xFFFFFFFFLL, 0LL);
v11 = v25;
if ( v25 == -1 )
{
puts("Error: Could not allocate page array using mmap. Terminating.");
perror("Failure reason");
return v4;
}
printf(
"sizeof(val) == %lu\nsizeof(page_array) == %lu\nsizeof(*(page_array)) == %lu\nsizeof(**page_array) == %lu\n",
8LL,
8LL,
8LL,
8LL);
printf("PAGE_SIZE == %lu\nwordsPerPage == %lu\n", 4096LL, 512LL);
puts("\n==============================\n");
puts("Hogging memory using mmap...");
v26 = (v6 << 8) & 0xFFFFFFFFFFFFFLL;
for ( i = 0LL; i != 0x400000; ++i )
{
if ( v26 == i )
break;
v27 = syscall(9LL, 0LL, 4096LL, 3LL, 34LL, 0xFFFFFFFFLL, 0LL);
*(_QWORD *)(v25 + 8 * i) = v27;
if ( v27 == -1 )
break;
}
if ( *(_QWORD *)(v25 + 8 * i) == -1LL )
{
if ( (i & 0x8000000000000000LL) != 0LL )
v28 = (double)(int)(i & 1 | (i >> 1)) + (double)(int)(i & 1 | (i >> 1));
else
v28 = (double)(int)i;
printf("Error: Failed to mmap page number %lu, at %0.2f MB.\n", i, v28 * 4096.0 * 0.00000095367431640625);
perror("Failure reason");
}
break;
default:
puts("Getting memory pointer array using malloc...");
v11 = (__int64)malloc(0x2000000uLL);
if ( !v11 )
{
puts("Error: Could not allocate page array using malloc. Terminating.");
perror("Failure reason");
return 1;
}
printf(
"sizeof(val) == %lu\nsizeof(page_array) == %lu\nsizeof(*(page_array)) == %lu\nsizeof(**page_array) == %lu\n",
8LL,
8LL,
8LL,
8LL);
printf("PAGE_SIZE == %lu\nwordsPerPage == %lu\n", 4096LL, 512LL);
puts("\n==============================\n");
puts("Hogging memory using malloc...");
v12 = v6 << 20;
v13 = (v6 << 8) & 0xFFFFFFFFFFFFFLL;
i = 0LL;
if ( v12 > 0xFFF )
{
while ( 1 )
{
v15 = malloc(0x1000uLL);
*(_QWORD *)(v11 + 8 * i) = v15;
if ( !v15 )
break;
if ( ++i == 0x400000 || i >= v13 )
goto LABEL_28;
}
if ( (i & 0x8000000000000000LL) != 0LL )
v30 = (double)(int)(i & 1 | (i >> 1)) + (double)(int)(i & 1 | (i >> 1));
else
v30 = (double)(int)i;
printf("Error: Failed to malloc page number %lu, at %0.2f MB.\n", i, v30 * 4096.0 * 0.00000095367431640625);
perror("Failure reason");
}
break;
}
LABEL_28:
if ( (i & 0x8000000000000000LL) != 0LL )
v16 = (double)(int)(i & 1 | (i >> 1)) + (double)(int)(i & 1 | (i >> 1));
else
v16 = (double)(int)i;
printf(
"We allocated %lu pages == %lu KB == %0.2f MB == %0.2f GB. Done.\n",
i,
(4 * i) & 0x3FFFFFFFFFFFFFLL,
v16 * 4096.0 * 0.00000095367431640625,
v16 * 4096.0 * 9.313225746154785e-10);
puts("\n==============================\n");
if ( v10 )
{
printf("Writing pattern: 0x%X %X\n", 0xFFFFFFFFLL, 0xFFFFFFFFLL);
v17 = (_QWORD *)(v11 + 8 * i);
while ( v56 >= v10 )
{
if ( v54 )
{
if ( i )
{
for ( j = 0LL; j != i; ++j )
{
v32 = (_QWORD *)(v11 + 8 * (rand() % i));
for ( k = 0LL; k != 4096; k += 8LL )
*(_QWORD *)(*v32 + k) = -1LL;
}
}
}
else if ( v53 )
{
v36 = (_QWORD *)v11;
if ( i )
{
do
{
v37 = 4096LL;
for ( l = 0LL; l != 4; ++l )
{
v39 = 8 * l;
do
{
*(_QWORD *)(*v36 + v39) = -1LL;
v39 += 32LL;
}
while ( v39 != v37 );
v37 += 8LL;
}
++v36;
}
while ( v36 != v17 );
}
}
else
{
v34 = (_QWORD *)v11;
if ( i )
{
do
{
for ( m = 0LL; m != 4096; m += 8LL )
*(_QWORD *)(*v34 + m) = -1LL;
++v34;
}
while ( v34 != v17 );
}
}
printf("Finished write iteration %d\n", (unsigned int)v10);
if ( seconds > 0 )
sleep(seconds);
++v10;
}
}
else
{
printf("Initializing memory with pattern: 0x%X %X\n", 0xFFFFFFFFLL, 0xFFFFFFFFLL);
for ( n = 0LL; i != n; ++n )
{
for ( ii = 0LL; ii != 4096; ii += 8LL )
*(_QWORD *)(*(_QWORD *)(v11 + 8 * n) + ii) = -1LL;
}
puts("Reading...");
for ( jj = 1; v56 >= jj; ++jj )
{
if ( v54 )
{
if ( i )
{
for ( kk = 0LL; kk != i; ++kk )
{
rand();
v44 = 512LL;
do
--v44;
while ( v44 );
}
}
}
else if ( v53 )
{
v47 = 0LL;
if ( i )
{
do
{
v48 = 4;
do
{
v49 = 128LL;
do
--v49;
while ( v49 );
--v48;
}
while ( v48 );
++v47;
}
while ( i != v47 );
}
}
else
{
v45 = 0LL;
if ( i )
{
do
{
v46 = 512LL;
do
--v46;
while ( v46 );
++v45;
}
while ( i != v45 );
}
}
printf("Finished read iteration %d\n", (unsigned int)jj);
if ( seconds > 0 )
sleep(seconds);
}
}
puts("Freeing memory...");
if ( (unsigned int)(v4 - 1) <= 1 )
{
for ( ll = 0LL; i != ll; ++ll )
munmap(*(void **)(v11 + 8 * ll), 0x1000uLL);
munmap((void *)v11, 0x400000uLL);
}
else
{
if ( i )
{
v50 = (void **)v11;
v51 = (void **)(v11 + 8 * i);
do
free(*v50++);
while ( v51 != v50 );
}
free((void *)v11);
}
puts("Done.");
v4 = 0;
}
else
{
fwrite(
"Invalid number of arguments: (1) Amount of memory to hog in MB, (2) Number of sleep seconds between iterations, (3"
") Allocator to use (M[malloc], m[mmap], V[vip_malloc], v[vip_mmap]), (4) Access pattern (n[sequential], s[staggere"
"d], r[random]), (5) Write or read (w[write], r[read]) (6) Number of iterations\n",
1uLL,
0x133uLL,
stderr);
v4 = 1;
}
return v4;
}

original_code:
int main(const int argc, const char *argv[]) {
 unsigned long MB_to_alloc = 0;
 unsigned long page = 0;
 unsigned long total_pages = 0;
 unsigned long val = 0;
 unsigned long word = 0;
 unsigned long **page_array = ((void *)0);
 int allocator_choice = 0;
 int stagger = 0;
 int staggerFlag = 0;
 int randomFlag = 0;
 unsigned long pageCount = 0;
 unsigned long wordsPerPage = 4096/sizeof(val);
 int writeFlag = 0;
 int sleepTime = 0;
 int numIters = 0;
 int iter = 1;
 srand(time(((void *)0)));
 if (argc != 7) {
  fprintf(stderr, "Invalid number of arguments: (1) Amount of memory to hog in MB, (2) Number of sleep seconds between iterations, (3) Allocator to use (M[malloc], m[mmap], V[vip_malloc], v[vip_mmap]), (4) Access pattern (n[sequential], s[staggered], r[random]), (5) Write or read (w[write], r[read]) (6) Number of iterations\n");
  return 1;
 }
 MB_to_alloc = (unsigned long) atol(argv[1]);
 printf("will alloc = %lu MB\n", MB_to_alloc);
 sleepTime = (int) atol(argv[2]);
 if (sleepTime < 0) {
  fprintf(stderr, "Sleep time was < 0s, setting to 0s.\n");
  sleepTime = 0;
 }
 printf("sleep time = %d s\n", sleepTime);
 if (argv[3][0] == 'v') {
  allocator_choice = 3;
  printf("allocator = vip_mmap\n");
 } else if (argv[3][0] == 'm') {
  allocator_choice = 1;
  printf("allocator = mmap\n");
 } else if (argv[3][0] == 'M') {
  allocator_choice = 0;
  printf("allocator = malloc\n");
 } else if (argv[3][0] == 'V' ) {
  allocator_choice = 2;
  printf("allocator = vip_malloc\n");
 } else {
  fprintf(stderr, "Bad allocator choice\n");
  return 1;
 }
 if (argv[4][0] == 's') {
  staggerFlag = 1;
  printf("access pattern = staggered\n");
 } else if (argv[4][0] == 'r') {
  randomFlag = 1;
  printf("access pattern = random\n");
  printf("RAND_MAX = %d\n", 2147483647);
 } else if (argv[4][0] == 'n') {
  printf("access pattern = sequential\n");
  randomFlag = 0;
  staggerFlag = 0;
 } else {
  fprintf(stderr, "Bad access pattern flag\n");
  return 1;
 }
 if (argv[5][0] == 'w') {
  writeFlag = 1;
  printf("access mode = write\n");
 } else if (argv[5][0] == 'r') {
  writeFlag = 0;
  printf("access mode = read\n");
 } else {
  fprintf(stderr, "Bad write/read input\n");
  return 1;
 }
 numIters = (int)atoi(argv[6]);
 if (numIters < 1) {
  fprintf(stderr, "Number of iterations was < 1, setting to 1\n");
  numIters = 1;
 }
 printf("num iterations = %d\n", numIters);
 printf("\n==============================\n\n");
 val = 0xFFFFFFFFFFFFFFFF;
 if (allocator_choice == 2) {
  printf("Getting memory pointer array using vip_malloc with vip_flags READ/HI...\n");
  if (!(page_array = vip_malloc(4194304*sizeof(unsigned long *), 0x0000 | 0x0020))) {
   printf("Error: Could not allocate page array using vip_malloc (READ/HI). Terminating.\n");
   perror("Failure reason");
   return 1;
  }
  } else if (allocator_choice == 3) {
  printf("Getting memory pointer array using vip_mmap with vip_flags READ/HI...\n");
  page_array = (unsigned long **) syscall(312, ((void *)0), 4194304*sizeof(unsigned long *), (0x1 | 0x2 | 0x0000 | 0x0020), (0x20 | 0x02), -1, 0);
  if (page_array == ((void *) -1)) {
   printf("Error: Could not allocate page array using vip_mmap (READ/HI). Terminating.\n");
   perror("Failure reason");
   return 1;
  }
 } else if (allocator_choice == 1) {
  printf("Getting memory pointer array using mmap...\n");
  page_array = (unsigned long **) syscall(9, ((void *)0), 4194304*sizeof(unsigned long *), (0x1 | 0x2), (0x20 | 0x02), -1, 0);
  if (page_array == ((void *) -1)) {
   printf("Error: Could not allocate page array using mmap. Terminating.\n");
   perror("Failure reason");
   return 1;
  }
 } else {
  printf("Getting memory pointer array using malloc...\n");
  if (!(page_array = malloc(4194304*sizeof(unsigned long *)))) {
   printf("Error: Could not allocate page array using malloc. Terminating.\n");
   perror("Failure reason");
   return 1;
  }
 }
 printf("sizeof(val) == %lu\nsizeof(page_array) == %lu\nsizeof(*(page_array)) == %lu\nsizeof(**page_array) == %lu\n", sizeof(val), sizeof(page_array), sizeof(*page_array), sizeof(**page_array));
 printf("PAGE_SIZE == %lu\nwordsPerPage == %lu\n", (unsigned long) 4096, (unsigned long) wordsPerPage);
 printf("\n==============================\n\n");
 if (allocator_choice == 2) {
  printf("Hogging memory using vip_malloc...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096)) {
   *(page_array+page) = vip_malloc(4096, 0x0000 | 0x0020);
   if (*(page_array+page) == ((void *)0)) {
    printf("Error: Failed to vip_malloc page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
    perror("Failure reason");
    break;
   }
   page++;
  }
 } else if (allocator_choice == 3) {
  printf("Hogging memory using vip_mmap with flags WRITE/HI...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096) && (*(page_array+page) = (unsigned long *) syscall(312, ((void *)0), 4096, (0x1 | 0x2 | 0x0010 | 0x0020), (0x20 | 0x02), -1, 0)) != ((void *) -1))
   page++;
  if (*(page_array+page) == ((void *) -1)) {
   printf("Error: Failed to vip_mmap page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
   perror("Failure reason");
  }
 } else if (allocator_choice == 1) {
  printf("Hogging memory using mmap...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096) && (*(page_array+page) = (unsigned long *) syscall(9, ((void *)0), 4096, (0x1 | 0x2), (0x20 | 0x02), -1, 0)) != ((void *) -1))
   page++;
  if (*(page_array+page) == ((void *) -1)) {
   printf("Error: Failed to mmap page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
   perror("Failure reason");
  }
 } else {
  printf("Hogging memory using malloc...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096)) {
   *(page_array+page) = malloc(4096);
   if (*(page_array+page) == ((void *)0)) {
    printf("Error: Failed to malloc page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
    perror("Failure reason");
    break;
   }
   page++;
  }
 }
 total_pages = page;
 printf("We allocated %lu pages == %lu KB == %0.2f MB == %0.2f GB. Done.\n", total_pages, total_pages*4096/1024, (double)total_pages*4096/(1024*1024), (double)total_pages*4096/(1024*1024*1024));
 printf("\n==============================\n\n");
 if (writeFlag) {
  printf("Writing pattern: 0x%X %X\n", (unsigned int) (val>>32), (unsigned int) val);
  for (iter = 1; iter <= numIters; iter++) {
   if (randomFlag) {
    for (pageCount = 0; pageCount < total_pages; pageCount++) {
     page = rand() % total_pages;
     for (word = 0; word < wordsPerPage; word++) {
      *(*(page_array+page)+word) = val;
     }
    }
   }
   else if (staggerFlag) {
    for (page = 0; page < total_pages; page++) {
     for (stagger = 0; stagger < 4; stagger++)
      for (word = 0; word < wordsPerPage; word=word+4) {
       *(*(page_array+page)+stagger+word) = val;
      }
    }
   }
   else {
    for (page = 0; page < total_pages; page++)
     for (word = 0; word < wordsPerPage; word++) {
      *(*(page_array+page)+word) = val;
     }
   }
   printf("Finished write iteration %d\n", iter);
   if (sleepTime > 0)
    sleep(sleepTime);
  }
 }
 else {
  printf("Initializing memory with pattern: 0x%X %X\n", (unsigned int) (val>>32), (unsigned int) val);
  for (page = 0; page < total_pages; page++)
   for (word = 0; word < wordsPerPage; word++)
    *(*(page_array+page)+word) = val;
  printf("Reading...\n");
  for (iter = 1; iter <= numIters; iter++) {
   if (randomFlag) {
    for (pageCount = 0; pageCount < total_pages; pageCount++) {
     page = rand() % total_pages;
     for (word = 0; word < wordsPerPage; word++) {
      val = *(*(page_array+page)+word);
     }
    }
   }
   else if (staggerFlag) {
    for (page = 0; page < total_pages; page++) {
     for (stagger = 0; stagger < 4; stagger++)
      for (word = 0; word < wordsPerPage; word=word+4) {
       val = *(*(page_array+page)+stagger+word);
       }
    }
   }
   else {
    for (page = 0; page < total_pages; page++)
     for (word = 0; word < wordsPerPage; word++) {
      val = *(*(page_array+page)+word);
     }
   }
   printf("Finished read iteration %d\n", iter);
   if (sleepTime > 0)
    sleep(sleepTime);
  }
 }
 printf("Freeing memory...\n");
 if (allocator_choice == 1 || allocator_choice == 2) {
  for (page = 0; page < total_pages; page++)
   munmap(*(page_array+page), 4096);
  munmap(page_array, 4194304);
 } else {
  for (page = 0; page < total_pages; page++)
   free(*(page_array+page));
  free(page_array);
 }
 printf("Done.\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 unsigned long MB_to_alloc = 0;
 unsigned long page = 0;
 unsigned long total_pages = 0;
 unsigned long val = 0;
 unsigned long word = 0;
 unsigned long **page_array = ((void *)0);
 int allocator_choice = 0;
 int stagger = 0;
 int staggerFlag = 0;
 int randomFlag = 0;
 unsigned long pageCount = 0;
 unsigned long wordsPerPage = 4096/sizeof(val);
 int writeFlag = 0;
 int sleepTime = 0;
 int numIters = 0;
 int iter = 1;
 srand(time(((void *)0)));
 if (argc != 7) {
  fprintf(stderr, "Invalid number of arguments: (1) Amount of memory to hog in MB, (2) Number of sleep seconds between iterations, (3) Allocator to use (M[malloc], m[mmap], V[vip_malloc], v[vip_mmap]), (4) Access pattern (n[sequential], s[staggered], r[random]), (5) Write or read (w[write], r[read]) (6) Number of iterations\n");
  return 1;
 }
 MB_to_alloc = (unsigned long) atol(argv[1]);
 printf("will alloc = %lu MB\n", MB_to_alloc);
 sleepTime = (int) atol(argv[2]);
 if (sleepTime < 0) {
  fprintf(stderr, "Sleep time was < 0s, setting to 0s.\n");
  sleepTime = 0;
 }
 printf("sleep time = %d s\n", sleepTime);
 if (argv[3][0] == 'v') {
  allocator_choice = 3;
  printf("allocator = vip_mmap\n");
 } else if (argv[3][0] == 'm') {
  allocator_choice = 1;
  printf("allocator = mmap\n");
 } else if (argv[3][0] == 'M') {
  allocator_choice = 0;
  printf("allocator = malloc\n");
 } else if (argv[3][0] == 'V' ) {
  allocator_choice = 2;
  printf("allocator = vip_malloc\n");
 } else {
  fprintf(stderr, "Bad allocator choice\n");
  return 1;
 }
 if (argv[4][0] == 's') {
  staggerFlag = 1;
  printf("access pattern = staggered\n");
 } else if (argv[4][0] == 'r') {
  randomFlag = 1;
  printf("access pattern = random\n");
  printf("RAND_MAX = %d\n", 2147483647);
 } else if (argv[4][0] == 'n') {
  printf("access pattern = sequential\n");
  randomFlag = 0;
  staggerFlag = 0;
 } else {
  fprintf(stderr, "Bad access pattern flag\n");
  return 1;
 }
 if (argv[5][0] == 'w') {
  writeFlag = 1;
  printf("access mode = write\n");
 } else if (argv[5][0] == 'r') {
  writeFlag = 0;
  printf("access mode = read\n");
 } else {
  fprintf(stderr, "Bad write/read input\n");
  return 1;
 }
 numIters = (int)atoi(argv[6]);
 if (numIters < 1) {
  fprintf(stderr, "Number of iterations was < 1, setting to 1\n");
  numIters = 1;
 }
 printf("num iterations = %d\n", numIters);
 printf("\n==============================\n\n");
 val = 0xFFFFFFFFFFFFFFFF;
 if (allocator_choice == 2) {
  printf("Getting memory pointer array using vip_malloc with vip_flags READ/HI...\n");
  if (!(page_array = vip_malloc(4194304*sizeof(unsigned long *), 0x0000 | 0x0020))) {
   printf("Error: Could not allocate page array using vip_malloc (READ/HI). Terminating.\n");
   perror("Failure reason");
   return 1;
  }
  } else if (allocator_choice == 3) {
  printf("Getting memory pointer array using vip_mmap with vip_flags READ/HI...\n");
  page_array = (unsigned long **) syscall(312, ((void *)0), 4194304*sizeof(unsigned long *), (0x1 | 0x2 | 0x0000 | 0x0020), (0x20 | 0x02), -1, 0);
  if (page_array == ((void *) -1)) {
   printf("Error: Could not allocate page array using vip_mmap (READ/HI). Terminating.\n");
   perror("Failure reason");
   return 1;
  }
 } else if (allocator_choice == 1) {
  printf("Getting memory pointer array using mmap...\n");
  page_array = (unsigned long **) syscall(9, ((void *)0), 4194304*sizeof(unsigned long *), (0x1 | 0x2), (0x20 | 0x02), -1, 0);
  if (page_array == ((void *) -1)) {
   printf("Error: Could not allocate page array using mmap. Terminating.\n");
   perror("Failure reason");
   return 1;
  }
 } else {
  printf("Getting memory pointer array using malloc...\n");
  if (!(page_array = malloc(4194304*sizeof(unsigned long *)))) {
   printf("Error: Could not allocate page array using malloc. Terminating.\n");
   perror("Failure reason");
   return 1;
  }
 }
 printf("sizeof(val) == %lu\nsizeof(page_array) == %lu\nsizeof(*(page_array)) == %lu\nsizeof(**page_array) == %lu\n", sizeof(val), sizeof(page_array), sizeof(*page_array), sizeof(**page_array));
 printf("PAGE_SIZE == %lu\nwordsPerPage == %lu\n", (unsigned long) 4096, (unsigned long) wordsPerPage);
 printf("\n==============================\n\n");
 if (allocator_choice == 2) {
  printf("Hogging memory using vip_malloc...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096)) {
   *(page_array+page) = vip_malloc(4096, 0x0000 | 0x0020);
   if (*(page_array+page) == ((void *)0)) {
    printf("Error: Failed to vip_malloc page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
    perror("Failure reason");
    break;
   }
   page++;
  }
 } else if (allocator_choice == 3) {
  printf("Hogging memory using vip_mmap with flags WRITE/HI...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096) && (*(page_array+page) = (unsigned long *) syscall(312, ((void *)0), 4096, (0x1 | 0x2 | 0x0010 | 0x0020), (0x20 | 0x02), -1, 0)) != ((void *) -1))
   page++;
  if (*(page_array+page) == ((void *) -1)) {
   printf("Error: Failed to vip_mmap page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
   perror("Failure reason");
  }
 } else if (allocator_choice == 1) {
  printf("Hogging memory using mmap...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096) && (*(page_array+page) = (unsigned long *) syscall(9, ((void *)0), 4096, (0x1 | 0x2), (0x20 | 0x02), -1, 0)) != ((void *) -1))
   page++;
  if (*(page_array+page) == ((void *) -1)) {
   printf("Error: Failed to mmap page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
   perror("Failure reason");
  }
 } else {
  printf("Hogging memory using malloc...\n");
  while ((page < 4194304) && (page < MB_to_alloc*1024*1024/4096)) {
   *(page_array+page) = malloc(4096);
   if (*(page_array+page) == ((void *)0)) {
    printf("Error: Failed to malloc page number %lu, at %0.2f MB.\n", page, (double)page*4096/(1024*1024));
    perror("Failure reason");
    break;
   }
   page++;
  }
 }
 total_pages = page;
 printf("We allocated %lu pages == %lu KB == %0.2f MB == %0.2f GB. Done.\n", total_pages, total_pages*4096/1024, (double)total_pages*4096/(1024*1024), (double)total_pages*4096/(1024*1024*1024));
 printf("\n==============================\n\n");
 if (writeFlag) {
  printf("Writing pattern: 0x%X %X\n", (unsigned int) (val>>32), (unsigned int) val);
  for (iter = 1; iter <= numIters; iter++) {
   if (randomFlag) {
    for (pageCount = 0; pageCount < total_pages; pageCount++) {
     page = rand() % total_pages;
     for (word = 0; word < wordsPerPage; word++) {
      *(*(page_array+page)+word) = val;
     }
    }
   }
   else if (staggerFlag) {
    for (page = 0; page < total_pages; page++) {
     for (stagger = 0; stagger < 4; stagger++)
      for (word = 0; word < wordsPerPage; word=word+4) {
       *(*(page_array+page)+stagger+word) = val;
      }
    }
   }
   else {
    for (page = 0; page < total_pages; page++)
     for (word = 0; word < wordsPerPage; word++) {
      *(*(page_array+page)+word) = val;
     }
   }
   printf("Finished write iteration %d\n", iter);
   if (sleepTime > 0)
    sleep(sleepTime);
  }
 }
 else {
  printf("Initializing memory with pattern: 0x%X %X\n", (unsigned int) (val>>32), (unsigned int) val);
  for (page = 0; page < total_pages; page++)
   for (word = 0; word < wordsPerPage; word++)
    *(*(page_array+page)+word) = val;
  printf("Reading...\n");
  for (iter = 1; iter <= numIters; iter++) {
   if (randomFlag) {
    for (pageCount = 0; pageCount < total_pages; pageCount++) {
     page = rand() % total_pages;
     for (word = 0; word < wordsPerPage; word++) {
      val = *(*(page_array+page)+word);
     }
    }
   }
   else if (staggerFlag) {
    for (page = 0; page < total_pages; page++) {
     for (stagger = 0; stagger < 4; stagger++)
      for (word = 0; word < wordsPerPage; word=word+4) {
       val = *(*(page_array+page)+stagger+word);
       }
    }
   }
   else {
    for (page = 0; page < total_pages; page++)
     for (word = 0; word < wordsPerPage; word++) {
      val = *(*(page_array+page)+word);
     }
   }
   printf("Finished read iteration %d\n", iter);
   if (sleepTime > 0)
    sleep(sleepTime);
  }
 }
 printf("Freeing memory...\n");
 if (allocator_choice == 1 || allocator_choice == 2) {
  for (page = 0; page < total_pages; page++)
   munmap(*(page_array+page), 4096);
  munmap(page_array, 4194304);
 } else {
  for (page = 0; page < total_pages; page++)
   free(*(page_array+page));
  free(page_array);
 }
 printf("Done.\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
page
unsigned long

variable_types:
val
unsigned long

variable_types:
word
unsigned long

variable_types: stagger int

variable_types: staggerFlag int

variable_types: randomFlag int

variable_types:
pageCount
unsigned long

variable_types:
wordsPerPage
unsigned long

variable_types: writeFlag int

variable_types: sleepTime int

variable_types: numIters int

variable_types: iter int


repo: nanpuyue/openwrt-extra

decompiled_code:
__int64 __fastcall mb_num_chars(char a1)
{
if ( (a1 & 0xE0) == 0xC0 )
return 2LL;
if ( (a1 & 0xF0) == 0xE0 )
return 3LL;
if ( (a1 & 0xF8) == 0xF0 )
return 4LL;
if ( (a1 & 0xFC) == 0xF8 )
return 5LL;
return 5 * (unsigned int)((a1 & 0xFE) == 0xFC) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
if ( (a1 & 0xE0) == 0xC0 )
return 2LL;
if ( (a1 & 0xF0) == 0xE0 )
return 3LL;
if ( (a1 & 0xF8) == 0xF0 )
return 4LL;
if ( (a1 & 0xFC) == 0xF8 )
return 5LL;
return 5 * (unsigned int)((a1 & 0xFE) == 0xFC) + 1;
}

original_code:
static inline int mb_num_chars(unsigned char c)
{
 if ((c & 0xE0) == 0xC0)
  return 2;
 else if ((c & 0xF0) == 0xE0)
  return 3;
 else if ((c & 0xF8) == 0xF0)
  return 4;
 else if ((c & 0xFC) == 0xF8)
  return 5;
 else if ((c & 0xFE) == 0xFC)
  return 6;
 return 1;
}

variable_types:
c
unsigned char


decompiled_code:
_BOOL8 __fastcall mb_is_cont(char a1)
{
return (unsigned __int8)(a1 + 0x80) <= 0x3Fu;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char a1)
{
return (unsigned __int8)(a1 + 0x80) <= 0x3Fu;
}

original_code:
static inline int mb_is_cont(unsigned char c)
{
 return ((c >= 0x80) && (c <= 0xBF));
}


variable_types:
s
unsigned char *

variable_types: n int


decompiled_code:
_BOOL8 __fastcall mb_is_surrogate(_BYTE *a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 == 3 && *a1 == 0xED )
result = (unsigned __int8)(a1[1] + 96) <= 0x1Fu;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_BYTE *a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 == 3 && *a1 == 0xED )
result = (unsigned __int8)(a1[1] + 96) <= 0x1Fu;
return result;
}

original_code:
static inline int mb_is_surrogate(unsigned char *s, int n)
{
 return ((n == 3) && (*s == 0xED) && (*(s+1) >= 0xA0) && (*(s+1) <= 0xBF));
}


decompiled_code:
_BOOL8 __fastcall mb_is_illegal(_BYTE *a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 == 3 && *a1 == 0xEF && a1[1] == 0xBF )
result = (unsigned __int8)(a1[2] + 66) <= 1u;
return result;
}

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

result = 0LL;
if ( a2 == 3 && *a1 == 0xEF && a1[1] == 0xBF )
result = (unsigned __int8)(a1[2] + 66) <= 1u;
return result;
}

original_code:
static inline int mb_is_illegal(unsigned char *s, int n)
{
 return ((n == 3) && (*s == 0xEF) && (*(s+1) == 0xBF) &&
   (*(s+2) >= 0xBE) && (*(s+2) <= 0xBF));
}


decompiled_code:
__int64 __fastcall buf_grow(__int64 a1, int a2)
{
int v3; // ebx
void *v4; // rdi
__int64 v5; // r12
char *v6; // rax
unsigned int v7; // ebx

v3 = a2;
v4 = *(void **)a1;
v5 = *(_QWORD *)(a1 + 8) - (_QWORD)v4;
if ( a2 <= 0 )
v3 = 1024;
v6 = (char *)realloc(v4, (unsigned int)(*(_DWORD *)(a1 + 16) + v3));
if ( !v6 )
return 0LL;
*(_QWORD *)a1 = v6;
*(_QWORD *)(a1 + 8) = &v6[(unsigned int)v5];
v7 = *(_DWORD *)(a1 + 16) + v3;
*(_DWORD *)(a1 + 16) = v7;
return v7;
}

original_code:
int buf_grow(struct template_buffer *buf, int size)
{
 unsigned int off = (buf->dptr - buf->data);
 char *data;
 if (size <= 0)
  size = 1024;
 data = realloc(buf->data, buf->size + size);
 if (data != ((void *)0))
 {
  buf->data = data;
  buf->dptr = data + off;
  buf->size += size;
  return buf->size;
 }
 return 0;
}

variable_types: struct template_buffer { char *data; char *dptr; unsigned int size; unsigned int fill; } *

variable_types: size int

variable_types:
off
unsigned int

variable_types:
data
char *


decompiled_code:
__int64 __fastcall buf_putchar(__int64 a1, char a2)
{
_BYTE *v2; // rax
__int64 result; // rax

if ( (unsigned int)(*(_DWORD *)(a1 + 20) + 1) < *(_DWORD *)(a1 + 16) || (result = buf_grow(a1, 0), (_DWORD)result) )
{
v2 = *(_BYTE **)(a1 + 8);
*(_QWORD *)(a1 + 8) = v2 + 1;
*v2 = a2;
**(_BYTE **)(a1 + 8) = 0;
++*(_DWORD *)(a1 + 20);
result = 1LL;
}
return result;
}

original_code:
int buf_putchar(struct template_buffer *buf, char c)
{
 if( ((buf->fill + 1) >= buf->size) && !buf_grow(buf, 0) )
  return 0;
 *(buf->dptr++) = c;
 *(buf->dptr) = 0;
 buf->fill++;
 return 1;
}

variable_types: c char

user_defined_types: struct template_buffer { char *data; char *dptr; unsigned int size; unsigned int fill; }


decompiled_code:
__int64 __fastcall buf_append(__int64 a1, const void *a2, unsigned int a3)
{
__int64 result; // rax
_BYTE *v5; // r12

if ( a3 + *(_DWORD *)(a1 + 20) + 1 < *(_DWORD *)(a1 + 16) || (result = buf_grow(a1, a3 + 1), (_DWORD)result) )
{
memcpy(*(void **)(a1 + 8), a2, (int)a3);
*(_DWORD *)(a1 + 20) += a3;
v5 = (_BYTE *)(*(_QWORD *)(a1 + 8) + (int)a3);
*(_QWORD *)(a1 + 8) = v5;
*v5 = 0;
result = a3;
}
return result;
}

original_code:
int buf_append(struct template_buffer *buf, const char *s, int len)
{
 if ((buf->fill + len + 1) >= buf->size)
 {
  if (!buf_grow(buf, len + 1))
   return 0;
 }
 memcpy(buf->dptr, s, len);
 buf->fill += len;
 buf->dptr += len;
 *(buf->dptr) = 0;
 return len;
}

canonical_original_code:
int buf_append(struct template_buffer *buf, char *s, int len)
{
 if ((buf->fill + len + 1) >= buf->size)
 {
  if (!buf_grow(buf, len + 1))
   return 0;
 }
 memcpy(buf->dptr, s, len);
 buf->fill += len;
 buf->dptr += len;
 *(buf->dptr) = 0;
 return len;
}

variable_types:
s
char *

variable_types: len int


decompiled_code:
__int64 __fastcall buf_length(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

original_code:
int buf_length(struct template_buffer *buf)
{
 return buf->fill;
}


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

v1 = *a1;
free(a1);
return v1;
}

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

v1 = *a1;
free(a1);
return v1;
}

original_code:
char * buf_destroy(struct template_buffer *buf)
{
 char *data = buf->data;
 free(buf);
 return data;
}

canonical_original_code:
char *buf_destroy(struct template_buffer *buf)
{
 char *data = buf->data;
 free(buf);
 return data;
}


striptags

original_code:
char * striptags(const char *s, unsigned int l)
{
 struct template_buffer *buf = buf_init(l);
 unsigned char *ptr = (unsigned char *)s;
 unsigned char *end = ptr + l;
 unsigned char *tag;
 unsigned char prev;
 char esq[8];
 int esl;
 for (prev = ' '; ptr < end; ptr++)
 {
  if ((*ptr == '<') && ((ptr + 2) < end) &&
   ((*(ptr + 1) == '/') || ((*__ctype_b_loc ())[(int) ((*(ptr + 1)))] & (unsigned short int) _ISalpha)))
  {
   for (tag = ptr; tag < end; tag++)
   {
    if (*tag == '>')
    {
     if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short int) _ISspace))
      buf_putchar(buf, ' ');
     ptr = tag;
     prev = ' ';
     break;
    }
   }
  }
  else if (((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short int) _ISspace))
  {
   if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short int) _ISspace))
    buf_putchar(buf, *ptr);
   prev = *ptr;
  }
  else
  {
   switch(*ptr)
   {
    case '"':
    case '\'':
    case '<':
    case '>':
    case '&':
     esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);
     buf_append(buf, esq, esl);
     break;
    default:
     buf_putchar(buf, *ptr);
     break;
   }
   prev = *ptr;
  }
 }
 return buf_destroy(buf);
}

canonical_original_code:
char *striptags(char *s, unsigned int l)
{
 struct template_buffer *buf = buf_init(l);
 unsigned char *ptr = (unsigned char *)s;
 unsigned char *end = ptr + l;
 unsigned char *tag;
 unsigned char prev;
 char esq[8];
 int esl;
 for (prev = ' '; ptr < end; ptr++)
 {
  if ((*ptr == '<') && ((ptr + 2) < end) &&
   ((*(ptr + 1) == '/') || ((*__ctype_b_loc ())[(int) ((*(ptr + 1)))] & (unsigned short) _ISalpha)))
  {
   for (tag = ptr; tag < end; tag++)
   {
    if (*tag == '>')
    {
     if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short) _ISspace))
      buf_putchar(buf, ' ');
     ptr = tag;
     prev = ' ';
     break;
    }
   }
  }
  else if (((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short) _ISspace))
  {
   if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short) _ISspace))
    buf_putchar(buf, *ptr);
   prev = *ptr;
  }
  else
  {
   switch(*ptr)
   {
    case '"':
    case '\'':
    case '<':
    case '>':
    case '&':
     esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);
     buf_append(buf, esq, esl);
     break;
    default:
     buf_putchar(buf, *ptr);
     break;
   }
   prev = *ptr;
  }
 }
 return buf_destroy(buf);
}

variable_types:
l
unsigned int

variable_types:
ptr
unsigned char *

variable_types:
end
unsigned char *

variable_types:
tag
unsigned char *

variable_types:
prev
unsigned char

variable_types:
esq
char [8]

variable_types: esl int


decompiled_code:
void __fastcall luastr_escape(__int64 a1, char *a2, int a3, int a4)
{
char *v4; // rbp
char *v5; // rbx
char v7; // al
int v8; // eax
char s[48]; // [rsp+8h] [rbp-30h] BYREF

v4 = &a2[a3];
if ( a2 < v4 )
{
v5 = a2;
while ( 1 )
{
v7 = *v5;
if ( *v5 <= 39 )
break;
if ( v7 == 92 )
{
buf_append(a1, "\\\\", 2u);
goto LABEL_7;
}
if ( v7 <= 92 && (v7 & 0xFD) == 60 )
goto LABEL_17;
LABEL_6:
buf_putchar(a1, *v5);
LABEL_7:
if ( ++v5 == v4 )
return;
}
if ( v7 <= 37 )
{
if ( v7 == 10 )
{
buf_append(a1, "\\n", 2u);
goto LABEL_7;
}
if ( v7 == 34 )
{
if ( a4 )
buf_append(a1, """, 5u);
else
buf_append(a1, "\\\"", 2u);
goto LABEL_7;
}
goto LABEL_6;
}
LABEL_17:
if ( a4 )
{
v8 = snprintf(s, 8uLL, "&#%i;", (unsigned int)v7);
buf_append(a1, s, v8);
goto LABEL_7;
}
goto LABEL_6;
}
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, char *a2, int a3, int a4)
{
char *v4; // rbp
char *v5; // rbx
char v7; // al
int v8; // eax
char s[48]; // [rsp+8h] [rbp-30h] BYREF

v4 = &a2[a3];
if ( a2 < v4 )
{
v5 = a2;
while ( 1 )
{
v7 = *v5;
if ( *v5 <= 39 )
break;
if ( v7 == 92 )
{
func7(a1, "\\\\", 2u);
goto LABEL_7;
}
if ( v7 <= 92 && (v7 & 0xFD) == 60 )
goto LABEL_17;
LABEL_6:
func6(a1, *v5);
LABEL_7:
if ( ++v5 == v4 )
return;
}
if ( v7 <= 37 )
{
if ( v7 == 10 )
{
func7(a1, "\\n", 2u);
goto LABEL_7;
}
if ( v7 == 34 )
{
if ( a4 )
func7(a1, """, 5u);
else
func7(a1, "\\\"", 2u);
goto LABEL_7;
}
goto LABEL_6;
}
LABEL_17:
if ( a4 )
{
v8 = snprintf(s, 8uLL, "&#%i;", (unsigned int)v7);
func7(a1, s, v8);
goto LABEL_7;
}
goto LABEL_6;
}
}

original_code:
void luastr_escape(struct template_buffer *out, const char *s, unsigned int l,
       int escape_xml)
{
 int esl;
 char esq[8];
 char *ptr;
 for (ptr = (char *)s; ptr < (s + l); ptr++)
 {
  switch (*ptr)
  {
  case '\\':
   buf_append(out, "\\\\", 2);
   break;
  case '"':
   if (escape_xml)
    buf_append(out, """, 5);
   else
    buf_append(out, "\\\"", 2);
   break;
  case '\n':
   buf_append(out, "\\n", 2);
   break;
  case '\'':
  case '&':
  case '<':
  case '>':
   if (escape_xml)
   {
    esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);
    buf_append(out, esq, esl);
    break;
   }
  default:
   buf_putchar(out, *ptr);
  }
 }
}

canonical_original_code:
void luastr_escape(struct template_buffer *out, char *s, unsigned int l, int escape_xml)
{
 int esl;
 char esq[8];
 char *ptr;
 for (ptr = (char *)s; ptr < (s + l); ptr++)
 {
  switch (*ptr)
  {
  case '\\':
   buf_append(out, "\\\\", 2);
   break;
  case '"':
   if (escape_xml)
    buf_append(out, """, 5);
   else
    buf_append(out, "\\\"", 2);
   break;
  case '\n':
   buf_append(out, "\\n", 2);
   break;
  case '\'':
  case '&':
  case '<':
  case '>':
   if (escape_xml)
   {
    esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);
    buf_append(out, esq, esl);
    break;
   }
  default:
   buf_putchar(out, *ptr);
  }
 }
}

variable_types:
ptr
char *


decompiled_code:
void __fastcall luastr_translate(__int64 a1, char *a2, unsigned int a3, int a4)
{
int v6; // eax
int v7; // [rsp+4h] [rbp-34h] BYREF
char *v8; // [rsp+8h] [rbp-30h] BYREF

v6 = lmo_translate(a2, a3, &v8, &v7);
if ( v6 == -1 )
{
luastr_escape(a1, a2, a3, a4);
}
else if ( !v6 )
{
luastr_escape(a1, v8, v7, a4);
}
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, char *a2, unsigned int a3, int a4)
{
int v6; // eax
int v7; // [rsp+4h] [rbp-34h] BYREF
char *v8; // [rsp+8h] [rbp-30h] BYREF

v6 = lmo_translate(a2, a3, &v8, &v7);
if ( v6 == -1 )
{
func12(a1, a2, a3, a4);
}
else if ( !v6 )
{
func12(a1, v8, v7, a4);
}
}

original_code:
void luastr_translate(struct template_buffer *out, const char *s, unsigned int l,
       int escape_xml)
{
 char *tr;
 int trlen;
 switch (lmo_translate(s, l, &tr, &trlen))
 {
  case 0:
   luastr_escape(out, tr, trlen, escape_xml);
   break;
  case -1:
   luastr_escape(out, s, l, escape_xml);
   break;
  default:
   break;
 }
}

canonical_original_code:
void luastr_translate(struct template_buffer *out, char *s, unsigned int l, int escape_xml)
{
 char *tr;
 int trlen;
 switch (lmo_translate(s, l, &tr, &trlen))
 {
  case 0:
   luastr_escape(out, tr, trlen, escape_xml);
   break;
  case -1:
   luastr_escape(out, s, l, escape_xml);
   break;
  default:
   break;
 }
}

variable_types:
tr
char *

variable_types: trlen int


decompiled_code:
unsigned int *__fastcall lmo_find_entry(__int64 a1, unsigned int a2)
{
unsigned int v2; // er13
unsigned int v3; // ebx
__int64 v4; // r15
unsigned int v5; // er12
unsigned int *v6; // rbp
unsigned int v7; // eax

v2 = *(_DWORD *)(a1 + 4) - 1;
v3 = v2 >> 1;
v4 = *(_QWORD *)(a1 + 16);
v5 = 0;
while ( 1 )
{
v6 = (unsigned int *)(v4 + 16LL * v3);
v7 = _bswap_32(*v6);
if ( v7 == a2 )
break;
if ( v7 <= a2 )
{
v5 = v3 + 1;
}
else
{
if ( !v3 )
return 0LL;
v2 = v3 - 1;
}
v3 = v5 + ((v2 - v5) >> 1);
if ( v2 < v5 )
return 0LL;
}
return v6;
}

canonical_decompiled_code:
unsigned int *__fastcall func1(__int64 a1, unsigned int a2)
{
unsigned int v2; // er13
unsigned int v3; // ebx
__int64 v4; // r15
unsigned int v5; // er12
unsigned int *v6; // rbp
unsigned int v7; // eax

v2 = *(_DWORD *)(a1 + 4) - 1;
v3 = v2 >> 1;
v4 = *(_QWORD *)(a1 + 16);
v5 = 0;
while ( 1 )
{
v6 = (unsigned int *)(v4 + 16LL * v3);
v7 = func0(*v6);
if ( v7 == a2 )
break;
if ( v7 <= a2 )
{
v5 = v3 + 1;
}
else
{
if ( !v3 )
return 0LL;
v2 = v3 - 1;
}
v3 = v5 + ((v2 - v5) >> 1);
if ( v2 < v5 )
return 0LL;
}
return v6;
}

original_code:
static lmo_entry_t * lmo_find_entry(lmo_archive_t *ar, uint32_t hash)
{
 unsigned int m, l, r;
 uint32_t k;
 l = 0;
 r = ar->length - 1;
 while (1)
 {
  m = l + ((r - l) / 2);
  if (r < l)
   break;
  k = ntohl(ar->index[m].key_id);
  if (k == hash)
   return &ar->index[m];
  if (k > hash)
  {
   if (!m)
    break;
   r = m - 1;
  }
  else
  {
   l = m + 1;
  }
 }
 return ((void *)0);
}

canonical_original_code:
static struct lmo_entry *lmo_find_entry(struct lmo_archive *ar, unsigned int hash)
{
 unsigned int m; unsigned int l; unsigned int r;
 unsigned int k;
 l = 0;
 r = ar->length - 1;
 while (1)
 {
  m = l + ((r - l) / 2);
  if (r < l)
   break;
  k = ntohl(ar->index[m].key_id);
  if (k == hash)
   return &ar->index[m];
  if (k > hash)
  {
   if (!m)
    break;
   r = m - 1;
  }
  else
  {
   l = m + 1;
  }
 }
 return ((void *)0);
}

variable_types: struct lmo_archive { int fd; int length; unsigned int size; struct lmo_entry *index; char *mmap; char *end; struct lmo_archive *next; } *

variable_types:
hash
unsigned int

variable_types:
m
unsigned int

variable_types:
r
unsigned int

variable_types:
k
unsigned int

return_type: struct lmo_entry { unsigned int key_id; unsigned int val_id; unsigned int offset; unsigned int length; } *


original_code:
uint32_t sfh_hash(const char *data, int len)
{
 uint32_t hash = len, tmp;
 int rem;
 if (len <= 0 || data == ((void *)0)) return 0;
 rem = len & 3;
 len >>= 2;
 for (;len > 0; len--) {
  hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
  tmp = (((((uint32_t)(((const uint8_t *)(data+2))[1])) << 8) +(uint32_t)(((const uint8_t *)(data+2))[0]) ) << 11) ^ hash;
  hash = (hash << 16) ^ tmp;
  data += 2*sizeof(uint16_t);
  hash += hash >> 11;
 }
 switch (rem) {
  case 3: hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
   hash ^= hash << 16;
   hash ^= data[sizeof(uint16_t)] << 18;
   hash += hash >> 11;
   break;
  case 2: hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
   hash ^= hash << 11;
   hash += hash >> 17;
   break;
  case 1: hash += *data;
   hash ^= hash << 10;
   hash += hash >> 1;
 }
 hash ^= hash << 3;
 hash += hash >> 5;
 hash ^= hash << 4;
 hash += hash >> 17;
 hash ^= hash << 25;
 hash += hash >> 6;
 return hash;
}

canonical_original_code:
unsigned int sfh_hash(char *data, int len)
{
 unsigned int hash = len; unsigned int tmp;
 int rem;
 if (len <= 0 || data == ((void *)0)) return 0;
 rem = len & 3;
 len >>= 2;
 for (;len > 0; len--) {
  hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
  tmp = (((((unsigned int)(((unsigned char *)(data+2))[1])) << 8) +(unsigned int)(((unsigned char *)(data+2))[0]) ) << 11) ^ hash;
  hash = (hash << 16) ^ tmp;
  data += 2*sizeof(unsigned short);
  hash += hash >> 11;
 }
 switch (rem) {
  case 3: hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
   hash ^= hash << 16;
   hash ^= data[sizeof(unsigned short)] << 18;
   hash += hash >> 11;
   break;
  case 2: hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
   hash ^= hash << 11;
   hash += hash >> 17;
   break;
  case 1: hash += *data;
   hash ^= hash << 10;
   hash += hash >> 1;
 }
 hash ^= hash << 3;
 hash += hash >> 5;
 hash ^= hash << 4;
 hash += hash >> 17;
 hash ^= hash << 25;
 hash += hash >> 6;
 return hash;
}

variable_types:
data
char *

variable_types:
tmp
unsigned int

variable_types: rem int

return_type: unsigned int


original_code:
uint32_t lmo_canon_hash(const char *str, int len)
{
 char res[4096];
 char *ptr, prev;
 int off;
 if (!str || len >= sizeof(res))
  return 0;
 for (prev = ' ', ptr = res, off = 0; off < len; prev = *str, off++, str++)
 {
  if (((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace))
  {
   if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short int) _ISspace))
    *ptr++ = ' ';
  }
  else
  {
   *ptr++ = *str;
  }
 }
 if ((ptr > res) && ((*__ctype_b_loc ())[(int) ((*(ptr-1)))] & (unsigned short int) _ISspace))
  ptr--;
 return sfh_hash(res, ptr - res);
}

canonical_original_code:
unsigned int lmo_canon_hash(char *str, int len)
{
 char res[4096];
 char *ptr; char prev;
 int off;
 if (!str || len >= sizeof(res))
  return 0;
 for (prev = ' ', ptr = res, off = 0; off < len; prev = *str, off++, str++)
 {
  if (((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace))
  {
   if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short) _ISspace))
    *ptr++ = ' ';
  }
  else
  {
   *ptr++ = *str;
  }
 }
 if ((ptr > res) && ((*__ctype_b_loc ())[(int) ((*(ptr-1)))] & (unsigned short) _ISspace))
  ptr--;
 return sfh_hash(res, ptr - res);
}

variable_types:
str
char *

variable_types: len int

variable_types:
res
char [4096]

variable_types: prev char

variable_types: off int


decompiled_code:
unsigned int *__fastcall lmo_open(char *file)
{
unsigned int *v1; // rbx
int v2; // ebp
unsigned int *v3; // rax
int v4; // eax
char *v5; // rax
char *v6; // r12
unsigned int v7; // er13
unsigned int v8; // eax
char *v9; // rdi
struct stat v11; // [rsp+0h] [rbp-B8h] BYREF

v1 = 0LL;
if ( stat(file, &v11) != -1 )
{
v2 = open(file, 0);
if ( v2 != -1 )
{
v3 = (unsigned int *)malloc(0x30uLL);
v1 = v3;
if ( v3 )
{
*(_QWORD *)v3 = 0LL;
*((_QWORD *)v3 + 1) = 0LL;
*((_QWORD *)v3 + 2) = 0LL;
*((_QWORD *)v3 + 3) = 0LL;
*((_QWORD *)v3 + 4) = 0LL;
*((_QWORD *)v3 + 5) = 0LL;
*v3 = v2;
v3[2] = v11.st_size;
v4 = fcntl(v2, 1);
fcntl(*v1, 2, v4 | 1u);
v5 = (char *)mmap(0LL, v1[2], 1, 1, *v1, 0LL);
v6 = v5;
*((_QWORD *)v1 + 3) = v5;
if ( v5 == (char *)-1LL )
{
if ( v2 < 0 )
{
LABEL_13:
free(v1);
return 0LL;
}
}
else
{
v7 = v1[2];
v8 = _bswap_32(*(_DWORD *)&v5[v7 - 4]);
if ( v7 > v8 )
{
*((_QWORD *)v1 + 2) = &v6[v8];
v1[1] = ((unsigned __int64)(v7 - v8) - 4) >> 4;
*((_QWORD *)v1 + 4) = &v6[v7];
return v1;
}
if ( v2 < 0 )
goto LABEL_11;
}
}
else if ( v2 < 0 )
{
return v1;
}
close(v2);
if ( !v1 )
return v1;
LABEL_11:
v9 = (char *)*((_QWORD *)v1 + 3);
if ( (unsigned __int64)(v9 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
munmap(v9, v1[2]);
goto LABEL_13;
}
}
return v1;
}

canonical_decompiled_code:
unsigned int *__fastcall func4(char *file)
{
unsigned int *v1; // rbx
int v2; // ebp
unsigned int *v3; // rax
int v4; // eax
char *v5; // rax
char *v6; // r12
unsigned int v7; // er13
unsigned int v8; // eax
char *v9; // rdi
struct stat v11; // [rsp+0h] [rbp-B8h] BYREF

v1 = 0LL;
if ( stat(file, &v11) != -1 )
{
v2 = open(file, 0);
if ( v2 != -1 )
{
v3 = (unsigned int *)malloc(0x30uLL);
v1 = v3;
if ( v3 )
{
*(_QWORD *)v3 = 0LL;
*((_QWORD *)v3 + 1) = 0LL;
*((_QWORD *)v3 + 2) = 0LL;
*((_QWORD *)v3 + 3) = 0LL;
*((_QWORD *)v3 + 4) = 0LL;
*((_QWORD *)v3 + 5) = 0LL;
*v3 = v2;
v3[2] = v11.st_size;
v4 = fcntl(v2, 1);
fcntl(*v1, 2, v4 | 1u);
v5 = (char *)mmap(0LL, v1[2], 1, 1, *v1, 0LL);
v6 = v5;
*((_QWORD *)v1 + 3) = v5;
if ( v5 == (char *)-1LL )
{
if ( v2 < 0 )
{
LABEL_13:
free(v1);
return 0LL;
}
}
else
{
v7 = v1[2];
v8 = func0(*(_DWORD *)&v5[v7 - 4]);
if ( v7 > v8 )
{
*((_QWORD *)v1 + 2) = &v6[v8];
v1[1] = ((unsigned __int64)(v7 - v8) - 4) >> 4;
*((_QWORD *)v1 + 4) = &v6[v7];
return v1;
}
if ( v2 < 0 )
goto LABEL_11;
}
}
else if ( v2 < 0 )
{
return v1;
}
close(v2);
if ( !v1 )
return v1;
LABEL_11:
v9 = (char *)*((_QWORD *)v1 + 3);
if ( (unsigned __int64)(v9 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
munmap(v9, v1[2]);
goto LABEL_13;
}
}
return v1;
}

original_code:
lmo_archive_t * lmo_open(const char *file)
{
 int in = -1;
 uint32_t idx_offset = 0;
 struct stat s;
 lmo_archive_t *ar = ((void *)0);
 if (stat(file, &s) == -1)
  goto err;
 if ((in = open(file, 00)) == -1)
  goto err;
 if ((ar = (lmo_archive_t *)malloc(sizeof(*ar))) != ((void *)0))
 {
  memset(ar, 0, sizeof(*ar));
  ar->fd = in;
  ar->size = s.st_size;
  fcntl(ar->fd, 2, fcntl(ar->fd, 1) | 1);
  if ((ar->mmap = mmap(((void *)0), ar->size, 0x1, 0x01, ar->fd, 0)) == ((void *) -1))
   goto err;
  idx_offset = ntohl(*((const uint32_t *)
                       (ar->mmap + ar->size - sizeof(uint32_t))));
  if (idx_offset >= ar->size)
   goto err;
  ar->index = (lmo_entry_t *)(ar->mmap + idx_offset);
  ar->length = (ar->size - idx_offset - sizeof(uint32_t)) / sizeof(lmo_entry_t);
  ar->end = ar->mmap + ar->size;
  return ar;
 }
err:
 if (in > -1)
  close(in);
 if (ar != ((void *)0))
 {
  if ((ar->mmap != ((void *)0)) && (ar->mmap != ((void *) -1)))
   munmap(ar->mmap, ar->size);
  free(ar);
 }
 return ((void *)0);
}

canonical_original_code:
struct lmo_archive *lmo_open(char *file)
{
 int in = -1;
 unsigned int idx_offset = 0;
 struct stat s;
 struct lmo_archive *ar = ((void *)0);
 if (stat(file, &s) == -1)
  goto err;
 if ((in = open(file, 00)) == -1)
  goto err;
 if ((ar = (struct lmo_archive *)malloc(sizeof(*ar))) != ((void *)0))
 {
  memset(ar, 0, sizeof(*ar));
  ar->fd = in;
  ar->size = s.st_size;
  fcntl(ar->fd, 2, fcntl(ar->fd, 1) | 1);
  if ((ar->mmap = mmap(((void *)0), ar->size, 0x1, 0x01, ar->fd, 0)) == ((void *) -1))
   goto err;
  idx_offset = ntohl(*((unsigned int *)
                       (ar->mmap + ar->size - sizeof(unsigned int))));
  if (idx_offset >= ar->size)
   goto err;
  ar->index = (struct lmo_entry *)(ar->mmap + idx_offset);
  ar->length = (ar->size - idx_offset - sizeof(unsigned int)) / sizeof(lmo_entry_t);
  ar->end = ar->mmap + ar->size;
  return ar;
 }
err:
 if (in > -1)
  close(in);
 if (ar != ((void *)0))
 {
  if ((ar->mmap != ((void *)0)) && (ar->mmap != ((void *) -1)))
   munmap(ar->mmap, ar->size);
  free(ar);
 }
 return ((void *)0);
}

variable_types:
file
char *

variable_types: in int

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

variable_types: struct lmo_archive { int fd; int length; unsigned int size; struct lmo_entry { unsigned int key_id; unsigned int val_id; unsigned int offset; unsigned int length; } *index; char *mmap; char *end; struct lmo_archive *next; } *

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

user_defined_types: struct lmo_archive { int fd; int length; unsigned int size; struct lmo_entry *index; char *mmap; char *end; struct lmo_archive *next; }


decompiled_code:
void __fastcall lmo_close(void *ptr)
{
char *v2; // rdi

if ( ptr )
{
v2 = (char *)*((_QWORD *)ptr + 3);
if ( (unsigned __int64)(v2 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
munmap(v2, *((unsigned int *)ptr + 2));
close(*(_DWORD *)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
char *v2; // rdi

if ( ptr )
{
v2 = (char *)*((_QWORD *)ptr + 3);
if ( (unsigned __int64)(v2 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
munmap(v2, *((unsigned int *)ptr + 2));
close(*(_DWORD *)ptr);
free(ptr);
}
}

original_code:
void lmo_close(lmo_archive_t *ar)
{
 if (ar != ((void *)0))
 {
  if ((ar->mmap != ((void *)0)) && (ar->mmap != ((void *) -1)))
   munmap(ar->mmap, ar->size);
  close(ar->fd);
  free(ar);
  ar = ((void *)0);
 }
}

canonical_original_code:
void lmo_close(struct lmo_archive *ar)
{
 if (ar != ((void *)0))
 {
  if ((ar->mmap != ((void *)0)) && (ar->mmap != ((void *) -1)))
   munmap(ar->mmap, ar->size);
  close(ar->fd);
  free(ar);
  ar = ((void *)0);
 }
}

user_defined_types: struct lmo_entry { unsigned int key_id; unsigned int val_id; unsigned int offset; unsigned int length; }


decompiled_code:
int __fastcall lmo_change_catalog(char *s2)
{
__int64 v1; // rbx
int result; // eax

v1 = lmo_catalogs;
if ( !lmo_catalogs )
return -1;
while ( 1 )
{
result = strncmp((const char *)v1, s2, 6uLL);
if ( !result )
break;
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return -1;
}
lmo_active_catalog = v1;
return result;
}

canonical_decompiled_code:
int __fastcall func6(char *s2)
{
__int64 v1; // rbx
int result; // eax

v1 = lmo_catalogs;
if ( !lmo_catalogs )
return -1;
while ( 1 )
{
result = strncmp((const char *)v1, s2, 6uLL);
if ( !result )
break;
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return -1;
}
lmo_active_catalog = v1;
return result;
}

original_code:
int lmo_change_catalog(const char *lang)
{
 lmo_catalog_t *cat;
 for (cat = _lmo_catalogs; cat; cat = cat->next)
 {
  if (!strncmp(cat->lang, lang, sizeof(cat->lang)))
  {
   _lmo_active_catalog = cat;
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
int lmo_change_catalog(char *lang)
{
 struct lmo_catalog *cat;
 for (cat = _lmo_catalogs; cat; cat = cat->next)
 {
  if (!strncmp(cat->lang, lang, sizeof(cat->lang)))
  {
   _lmo_active_catalog = cat;
   return 0;
  }
 }
 return -1;
}

variable_types:
lang
char *

variable_types: struct lmo_catalog { char lang[6]; struct lmo_archive { int fd; int length; unsigned int size; struct lmo_entry { unsigned int key_id; unsigned int val_id; unsigned int offset; unsigned int length; } *index; char *mmap; char *end; struct lmo_archive *next; } *archives; struct lmo_catalog *next; } *

user_defined_types: struct lmo_catalog { char lang[6]; struct lmo_archive *archives; struct lmo_catalog *next; }


decompiled_code:
__int64 __fastcall lmo_translate(char *a1, int a2, _QWORD *a3, _DWORD *a4)
{
unsigned int v6; // er12
__int64 v7; // rbx
unsigned int *v8; // rax
unsigned int *v9; // rbp

if ( !a1 )
return 4294967294LL;
if ( !lmo_active_catalog )
return 4294967294LL;
v6 = lmo_canon_hash(a1, a2);
v7 = *(_QWORD *)(lmo_active_catalog + 8LL);
if ( !v7 )
return 0xFFFFFFFFLL;
while ( 1 )
{
v8 = lmo_find_entry(v7, v6);
v9 = v8;
if ( v8 )
break;
v7 = *(_QWORD *)(v7 + 40);
if ( !v7 )
return 0xFFFFFFFFLL;
}
*a3 = *(_QWORD *)(v7 + 24) + (unsigned int)_bswap_32(v8[2]);
*a4 = _bswap_32(v9[3]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, int a2, _QWORD *a3, _DWORD *a4)
{
unsigned int v6; // er12
__int64 v7; // rbx
unsigned int *v8; // rax
unsigned int *v9; // rbp

if ( !a1 )
return 4294967294LL;
if ( !lmo_active_catalog )
return 4294967294LL;
v6 = func3(a1, a2);
v7 = *(_QWORD *)(lmo_active_catalog + 8LL);
if ( !v7 )
return 0xFFFFFFFFLL;
while ( 1 )
{
v8 = func1(v7, v6);
v9 = v8;
if ( v8 )
break;
v7 = *(_QWORD *)(v7 + 40);
if ( !v7 )
return 0xFFFFFFFFLL;
}
*a3 = *(_QWORD *)(v7 + 24) + (unsigned int)func0(v8[2]);
*a4 = func0(v9[3]);
return 0LL;
}

original_code:
int lmo_translate(const char *key, int keylen, char **out, int *outlen)
{
 uint32_t hash;
 lmo_entry_t *e;
 lmo_archive_t *ar;
 if (!key || !_lmo_active_catalog)
  return -2;
 hash = lmo_canon_hash(key, keylen);
 for (ar = _lmo_active_catalog->archives; ar; ar = ar->next)
 {
  if ((e = lmo_find_entry(ar, hash)) != ((void *)0))
  {
   *out = ar->mmap + ntohl(e->offset);
   *outlen = ntohl(e->length);
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
int lmo_translate(char *key, int keylen, char **out, int *outlen)
{
 unsigned int hash;
 struct lmo_entry *e;
 struct lmo_archive *ar;
 if (!key || !_lmo_active_catalog)
  return -2;
 hash = lmo_canon_hash(key, keylen);
 for (ar = _lmo_active_catalog->archives; ar; ar = ar->next)
 {
  if ((e = lmo_find_entry(ar, hash)) != ((void *)0))
  {
   *out = ar->mmap + ntohl(e->offset);
   *outlen = ntohl(e->length);
   return 0;
  }
 }
 return -1;
}

variable_types:
key
char *

variable_types: keylen int

variable_types:
out
char **

variable_types:
outlen
int *

variable_types:
hash
unsigned int

variable_types: struct lmo_entry { unsigned int key_id; unsigned int val_id; unsigned int offset; unsigned int length; } *


decompiled_code:
void __fastcall lmo_close_catalog(char *s2)
{
__int64 v1; // rbx
__int64 v2; // r12
_QWORD *v3; // rbp
void *v4; // rdi

v1 = lmo_catalogs;
if ( lmo_catalogs )
{
v2 = 0LL;
while ( strncmp((const char *)v1, s2, 6uLL) )
{
v2 = v1;
if ( !*(_QWORD *)(v1 + 16) )
return;
v1 = *(_QWORD *)(v1 + 16);
}
if ( v2 )
*(_QWORD *)(v2 + 16) = *(_QWORD *)(v1 + 16);
else
lmo_catalogs = *(_QWORD *)(v1 + 16);
v3 = *(_QWORD **)(v1 + 8);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[5];
lmo_close(v4);
}
free((void *)v1);
}
}

canonical_decompiled_code:
void __fastcall func9(char *s2)
{
__int64 v1; // rbx
__int64 v2; // r12
_QWORD *v3; // rbp
void *v4; // rdi

v1 = lmo_catalogs;
if ( lmo_catalogs )
{
v2 = 0LL;
while ( strncmp((const char *)v1, s2, 6uLL) )
{
v2 = v1;
if ( !*(_QWORD *)(v1 + 16) )
return;
v1 = *(_QWORD *)(v1 + 16);
}
if ( v2 )
*(_QWORD *)(v2 + 16) = *(_QWORD *)(v1 + 16);
else
lmo_catalogs = *(_QWORD *)(v1 + 16);
v3 = *(_QWORD **)(v1 + 8);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[5];
func5(v4);
}
free((void *)v1);
}
}

original_code:
void lmo_close_catalog(const char *lang)
{
 lmo_archive_t *ar, *next;
 lmo_catalog_t *cat, *prev;
 for (prev = ((void *)0), cat = _lmo_catalogs; cat; prev = cat, cat = cat->next)
 {
  if (!strncmp(cat->lang, lang, sizeof(cat->lang)))
  {
   if (prev)
    prev->next = cat->next;
   else
    _lmo_catalogs = cat->next;
   for (ar = cat->archives; ar; ar = next)
   {
    next = ar->next;
    lmo_close(ar);
   }
   free(cat);
   break;
  }
 }
}

canonical_original_code:
void lmo_close_catalog(char *lang)
{
 struct lmo_archive *ar; struct lmo_archive *next;
 struct lmo_catalog *cat; struct lmo_catalog *prev;
 for (prev = ((void *)0), cat = _lmo_catalogs; cat; prev = cat, cat = cat->next)
 {
  if (!strncmp(cat->lang, lang, sizeof(cat->lang)))
  {
   if (prev)
    prev->next = cat->next;
   else
    _lmo_catalogs = cat->next;
   for (ar = cat->archives; ar; ar = next)
   {
    next = ar->next;
    lmo_close(ar);
   }
   free(cat);
   break;
  }
 }
}


decompiled_code:
__int64 __fastcall cmp_index(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 >= *(_DWORD *)a2 )
result = *(_DWORD *)a1 > *(_DWORD *)a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 >= *(_DWORD *)a2 )
result = *(_DWORD *)a1 > *(_DWORD *)a2;
return result;
}

original_code:
static int cmp_index(const void *a, const void *b)
{
 uint32_t x = ((const lmo_entry_t *)a)->key_id;
 uint32_t y = ((const lmo_entry_t *)b)->key_id;
 if (x < y)
  return -1;
 else if (x > y)
  return 1;
 return 0;
}

canonical_original_code:
static int cmp_index(void *a, void *b)
{
 unsigned int x = ((const lmo_entry_t *)a)->key_id;
 unsigned int y = ((const lmo_entry_t *)b)->key_id;
 if (x < y)
  return -1;
 else if (x > y)
  return 1;
 return 0;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
x
unsigned int

variable_types:
y
unsigned int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "Usage: %s input.po output.lmo\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
fprintf(stderr, "Usage: %s input.po output.lmo\n", a1);
exit(1);
}

original_code:
static void usage(const char *name)
{
 fprintf(stderr, "Usage: %s input.po output.lmo\n", name);
 exit(1);
}

canonical_original_code:
static void usage(char *name)
{
 fprintf(stderr, "Usage: %s input.po output.lmo\n", name);
 exit(1);
}

variable_types:
name
char *


die

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
fprintf(stderr, "Error: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
fprintf(stderr, "Error: %s\n", a1);
exit(1);
}

original_code:
static void die(const char *msg)
{
 fprintf(stderr, "Error: %s\n", msg);
 exit(1);
}

canonical_original_code:
static void die(char *msg)
{
 fprintf(stderr, "Error: %s\n", msg);
 exit(1);
}

variable_types:
msg
char *


KeyGenFunc

repo: naphthalene/tnetris

decompiled_code:
__int64 __fastcall KeyGenFunc(__int64 a1, __int64 a2)
{
return 2 * (unsigned int)((unsigned int)MyRead(*(unsigned int *)(a1 + 16), a2 + 8, 1LL) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return 2 * (unsigned int)((unsigned int)MyRead(*(unsigned int *)(a1 + 16), a2 + 8, 1LL) != 0);
}

original_code:
static MyEventType KeyGenFunc(EventGenRec *gen, MyEvent *event)
{
 if (MyRead(gen->fd, &event->u.key, 1))
  return E_key;
 else
  return E_none;
}

canonical_original_code:
static enum _MyEventType KeyGenFunc(struct _EventGenRec *gen, struct _MyEvent *event)
{
 if (MyRead(gen->fd, &event->u.key, 1))
  return E_key;
 else
  return E_none;
}

variable_types: struct _EventGenRec { struct _EventGenRec *next; int ready; enum _FDType { FT_read=0, FT_write=1, FT_except=2, FT_len=3 } fdType; int fd; enum _MyEventType { E_none=0, E_alarm=1, E_key=2, E_net=3, E_lostConn=4, E_robot=5, E_lostRobot=6 } (*func)(struct _EventGenRec *gen, struct _MyEvent { enum _MyEventType { E_none=0, E_alarm=1, E_key=2, E_net=3, E_lostConn=4, E_robot=5, E_lostRobot=6 } type; union { char key; struct { enum _NetPacketType { NP_endConn=0, NP_giveJunk=1, NP_newPiece=2, NP_down=3, NP_left=4, NP_right=5, NP_rotate=6, NP_drop=7, NP_clear=8, NP_insertJunk=9, NP_startConn=10, NP_userName=11, NP_pause=12, NP_version=13, NP_byeBye=14 } type; int size; void *data; } net; struct { int size; char *data; } robot; } u; } *event); int mask; } *

variable_types:
event
struct _MyEvent *

user_defined_types: struct _EventGenRec { struct _EventGenRec *next; int ready; enum _FDType fdType; int fd; enum _MyEventType (*func)(struct _EventGenRec *gen, struct _MyEvent *event); int mask; }

user_defined_types: struct _MyEvent { enum _MyEventType type; union { char key; struct { enum _NetPacketType type; int size; void *data; } net; struct { int size; char *data; } robot; } u; }


decompiled_code:
int __fastcall PlotBlock1(int a1, int a2, int a3, char a4)
{
const char *v5; // rsi

wmove(stdscr, boardYPos[a1] - a2, boardXPos[a1] + 2 * a3);
if ( !a4 )
return waddnstr(stdscr, " ", -1);
if ( standoutEnable )
{
if ( haveColor )
wattrset(stdscr, abs8(a4) << 8);
else
wattrset(stdscr, 0x10000);
}
v5 = (const char *)&unk_A58;
if ( a4 <= 0 )
v5 = "$$";
waddnstr(stdscr, v5, -1);
return wattrset(stdscr, 0);
}

canonical_decompiled_code:
int __fastcall func1(int a1, int a2, int a3, char a4)
{
const char *v5; // rsi

wmove(stdscr, boardYPos[a1] - a2, boardXPos[a1] + 2 * a3);
if ( !a4 )
return waddnstr(stdscr, " ", -1);
if ( standoutEnable )
{
if ( haveColor )
wattrset(stdscr, abs8(a4) << 8);
else
wattrset(stdscr, 0x10000);
}
v5 = (const char *)&unk_A58;
if ( a4 <= 0 )
v5 = "$$";
waddnstr(stdscr, v5, -1);
return wattrset(stdscr, 0);
}

original_code:
static void PlotBlock1(int scr, int y, int x, BlockType type)
{
 int colorIndex = abs(type);
 wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] + 2 * x));
 if (type == BT_none)
  waddnstr(stdscr,("  "),-1);
 else
 {
  if (standoutEnable)
  {
   if (haveColor)
    wattrset(stdscr,((((chtype)(((colorIndex))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))));
   else
    (wattrset(stdscr,((chtype)((1U)) << ((8) + 8))));
  }
  waddnstr(stdscr,(type > 0 ? "[]" : "$$"),-1);
  (wattrset(stdscr,(1U - 1U)));
 }
}

canonical_original_code:
static void PlotBlock1(int scr, int y, int x, char type)
{
 int colorIndex = abs(type);
 wmove(stdscr,(boardYPos[scr] - y),(boardXPos[scr] + 2 * x));
 if (type == BT_none)
  waddnstr(stdscr,("  "),-1);
 else
 {
  if (standoutEnable)
  {
   if (haveColor)
    wattrset(stdscr,((((chtype)(((colorIndex))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))));
   else
    (wattrset(stdscr,((chtype)((1U)) << ((8) + 8))));
  }
  waddnstr(stdscr,(type > 0 ? "[]" : "$$"),-1);
  (wattrset(stdscr,(1U - 1U)));
 }
}

variable_types: scr int

variable_types: y int

variable_types: x int

variable_types: type char

variable_types: colorIndex int