decompiled_code:
__int64 __fastcall meh_finish_hash(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 || !a2 )
return meh_error("invalid argument passed to meh_finish_hash", 4294967291LL);
switch ( *((_DWORD *)a1 + 2) )
{
case 0:
meh_finish_md5(*a1);
result = 0LL;
break;
case 1:
meh_finish_sha1(*a1);
result = 0LL;
break;
case 2:
case 3:
meh_finish_sha256(*a1);
result = 0LL;
break;
case 4:
case 5:
meh_finish_sha512(*a1);
result = 0LL;
break;
default:
result = meh_error("invalid hash id passed to meh_finish_hash", 4294967286LL);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 || !a2 )
return meh_error("invalid argument passed to meh_finish_hash", 4294967291LL);
switch ( *((_DWORD *)a1 + 2) )
{
case 0:
meh_finish_md5(*a1);
result = 0LL;
break;
case 1:
meh_finish_sha1(*a1);
result = 0LL;
break;
case 2:
case 3:
meh_finish_sha256(*a1);
result = 0LL;
break;
case 4:
case 5:
meh_finish_sha512(*a1);
result = 0LL;
break;
default:
result = meh_error("invalid hash id passed to meh_finish_hash", 4294967286LL);
break;
}
return result;
}

original_code:
meh_error_t meh_finish_hash(MehHash hash, unsigned char* output)
{
    if (((void *)0) == hash || ((void *)0) == output)
        return meh_error("invalid argument passed to meh_finish_hash",
                         MEH_INVALID_ARGUMENT);
    switch (hash->id)
    {
        case MEH_MD5: meh_finish_md5(hash->state.md5, output); break;
        case MEH_SHA1: meh_finish_sha1(hash->state.sha1, output); break;
        case MEH_SHA224: meh_finish_sha256((hash->state.sha224), (output)); break;
        case MEH_SHA256: meh_finish_sha256(hash->state.sha256, output); break;
        case MEH_SHA384: meh_finish_sha512((hash->state.sha384), (output)); break;
        case MEH_SHA512: meh_finish_sha512(hash->state.sha512, output); break;
        default:
            return meh_error("invalid hash id passed to meh_finish_hash",
                             MEH_INVALID_HASH);
    }
    return MEH_OK;
}

canonical_original_code:
enum meh_error_t meh_finish_hash(struct meh_hash_s *hash, unsigned char *output)
{
    if (((void *)0) == hash || ((void *)0) == output)
        return meh_error("invalid argument passed to meh_finish_hash",
                         MEH_INVALID_ARGUMENT);
    switch (hash->id)
    {
        case MEH_MD5: meh_finish_md5(hash->state.md5, output); break;
        case MEH_SHA1: meh_finish_sha1(hash->state.sha1, output); break;
        case MEH_SHA224: meh_finish_sha256((hash->state.sha224), (output)); break;
        case MEH_SHA256: meh_finish_sha256(hash->state.sha256, output); break;
        case MEH_SHA384: meh_finish_sha512((hash->state.sha384), (output)); break;
        case MEH_SHA512: meh_finish_sha512(hash->state.sha512, output); break;
        default:
            return meh_error("invalid hash id passed to meh_finish_hash",
                             MEH_INVALID_HASH);
    }
    return MEH_OK;
}

variable_types:
output
unsigned char *


repo: thomdixon/libmeh

decompiled_code:
void __fastcall meh_destroy_hash(void *ptr)
{
if ( ptr )
{
switch ( *((_DWORD *)ptr + 2) )
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
free(*(void **)ptr);
break;
default:
meh_warn("invalid hash id passed to meh_destroy_hash");
break;
}
free(ptr);
}
else
{
meh_warn("invalid argument passed to meh_destroy_hash");
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
switch ( *((_DWORD *)ptr + 2) )
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
free(*(void **)ptr);
break;
default:
meh_warn("invalid hash id passed to meh_destroy_hash");
break;
}
free(ptr);
}
else
{
meh_warn("invalid argument passed to meh_destroy_hash");
}
}

original_code:
void meh_destroy_hash(MehHash hash)
{
    if (((void *)0) == hash)
    {
        meh_warn("invalid argument passed to meh_destroy_hash");
        return;
    }
    switch (hash->id)
    {
        case MEH_MD5: free(hash->state.md5); break;
        case MEH_SHA1: free(hash->state.sha1); break;
        case MEH_SHA224: free(hash->state.sha224); break;
        case MEH_SHA256: free(hash->state.sha256); break;
        case MEH_SHA384: free(hash->state.sha384); break;
        case MEH_SHA512: free(hash->state.sha512); break;
        default:
            meh_warn("invalid hash id passed to meh_destroy_hash");
    }
    free(hash);
}

canonical_original_code:
void meh_destroy_hash(struct meh_hash_s *hash)
{
    if (((void *)0) == hash)
    {
        meh_warn("invalid argument passed to meh_destroy_hash");
        return;
    }
    switch (hash->id)
    {
        case MEH_MD5: free(hash->state.md5); break;
        case MEH_SHA1: free(hash->state.sha1); break;
        case MEH_SHA224: free(hash->state.sha224); break;
        case MEH_SHA256: free(hash->state.sha256); break;
        case MEH_SHA384: free(hash->state.sha384); break;
        case MEH_SHA512: free(hash->state.sha512); break;
        default:
            meh_warn("invalid hash id passed to meh_destroy_hash");
    }
    free(hash);
}

variable_types: struct meh_hash_s { union meh_hash_state_u { struct meh_md5_state_s { unsigned int total[2]; unsigned char buffer[64]; } *md5; struct meh_sha1_state_s { unsigned int total[2]; unsigned char buffer[64]; } *sha1; struct meh_sha256_state_s { unsigned int total[2]; unsigned char buffer[64]; } *sha256; struct meh_sha256_state_s *sha224; struct meh_sha512_state_s { unsigned int total[2]; unsigned long state[8]; unsigned char buffer[128]; } *sha384; struct meh_sha512_state_s *sha512; } state; enum meh_hash_id { MEH_MD5=0, MEH_SHA1=1, MEH_SHA224=2, MEH_SHA256=3, MEH_SHA384=4, MEH_SHA512=5 } id; unsigned long output_size; } *

return_type: void

user_defined_types: struct meh_hash_s { union meh_hash_state_u state; enum meh_hash_id id; unsigned long output_size; }

user_defined_types: union meh_hash_state_u { struct meh_md5_state_s *md5; struct meh_sha1_state_s *sha1; struct meh_sha256_state_s *sha256; struct meh_sha256_state_s *sha224; struct meh_sha512_state_s *sha384; struct meh_sha512_state_s *sha512; }


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

switch ( *(_DWORD *)(a1 + 8) )
{
case 0:
result = 16LL;
break;
case 1:
result = 20LL;
break;
case 2:
result = 28LL;
break;
case 3:
result = 32LL;
break;
case 4:
result = 48LL;
break;
case 5:
result = 64LL;
break;
default:
result = (int)meh_error("invalid hash id passed to meh_hash_output_size", 0xFFFFFFFFLL);
break;
}
return result;
}

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

switch ( *(_DWORD *)(a1 + 8) )
{
case 0:
result = 16LL;
break;
case 1:
result = 20LL;
break;
case 2:
result = 28LL;
break;
case 3:
result = 32LL;
break;
case 4:
result = 48LL;
break;
case 5:
result = 64LL;
break;
default:
result = (int)meh_error("invalid hash id passed to meh_hash_output_size", 0xFFFFFFFFLL);
break;
}
return result;
}

original_code:
size_t meh_hash_output_size(MehHash hash)
{
    switch (hash->id)
    {
        case MEH_MD5: return 16;
        case MEH_SHA1: return 20;
        case MEH_SHA224: return 28;
        case MEH_SHA256: return 32;
        case MEH_SHA384: return 48;
        case MEH_SHA512: return 64;
        default:
            return meh_error(
                "invalid hash id passed to meh_hash_output_size", -1);
    }
    return -1;
}

canonical_original_code:
unsigned long meh_hash_output_size(struct meh_hash_s *hash)
{
    switch (hash->id)
    {
        case MEH_MD5: return 16;
        case MEH_SHA1: return 20;
        case MEH_SHA224: return 28;
        case MEH_SHA256: return 32;
        case MEH_SHA384: return 48;
        case MEH_SHA512: return 64;
        default:
            return meh_error(
                "invalid hash id passed to meh_hash_output_size", -1);
    }
    return -1;
}

return_type: unsigned long

user_defined_types: enum meh_hash_id { MEH_MD5=0, MEH_SHA1=1, MEH_SHA224=2, MEH_SHA256=3, MEH_SHA384=4, MEH_SHA512=5 }

user_defined_types: struct meh_md5_state_s { unsigned int total[2]; unsigned char buffer[64]; }

user_defined_types: struct meh_sha1_state_s { unsigned int total[2]; unsigned char buffer[64]; }

user_defined_types: struct meh_sha256_state_s { unsigned int total[2]; unsigned char buffer[64]; }

user_defined_types: struct meh_sha512_state_s { unsigned int total[2]; unsigned long state[8]; unsigned char buffer[128]; }


decompiled_code:
__int64 __fastcall meh_hash_block_size(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // rdx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 8);
v2 = 64LL;
if ( v1 > 3 && (v2 = 128LL, v1 - 4 > 1) )
result = (int)meh_error("invalid hash id passed to meh_hash_block_size", 0xFFFFFFFFLL);
else
result = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // rdx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 8);
v2 = 64LL;
if ( v1 > 3 && (v2 = 128LL, v1 - 4 > 1) )
result = (int)meh_error("invalid hash id passed to meh_hash_block_size", 0xFFFFFFFFLL);
else
result = v2;
return result;
}

original_code:
size_t meh_hash_block_size(MehHash hash)
{
    switch (hash->id)
    {
        case MEH_MD5: return 64;
        case MEH_SHA1: return 64;
        case MEH_SHA224: return 64;
        case MEH_SHA256: return 64;
        case MEH_SHA384: return 128;
        case MEH_SHA512: return 128;
        default:
            return meh_error(
                "invalid hash id passed to meh_hash_block_size", -1);
    }
    return -1;
}

canonical_original_code:
unsigned long meh_hash_block_size(struct meh_hash_s *hash)
{
    switch (hash->id)
    {
        case MEH_MD5: return 64;
        case MEH_SHA1: return 64;
        case MEH_SHA224: return 64;
        case MEH_SHA256: return 64;
        case MEH_SHA384: return 128;
        case MEH_SHA512: return 128;
        default:
            return meh_error(
                "invalid hash id passed to meh_hash_block_size", -1);
    }
    return -1;
}


decompiled_code:
__int64 __fastcall meh_hash(int a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 *v6; // rax
__int64 *v7; // rbp
unsigned int v8; // ebx

v6 = meh_get_hash(a1);
if ( !v6 )
return (unsigned int)-1;
v7 = v6;
v8 = meh_update_hash(v6, a2, a3);
if ( !v8 )
v8 = meh_finish_hash(v7, a4);
meh_destroy_hash(v7);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 *v6; // rax
__int64 *v7; // rbp
unsigned int v8; // ebx

v6 = meh_get_hash(a1);
if ( !v6 )
return (unsigned int)-1;
v7 = v6;
v8 = func1(v6, a2, a3);
if ( !v8 )
v8 = func2(v7, a4);
func3(v7);
return v8;
}

original_code:
meh_error_t meh_hash(meh_hash_id hash_id, const unsigned char* data,
                     size_t len, unsigned char* output)
{
    meh_error_t error;
    MehHash t;
    t = meh_get_hash(hash_id);
    if (((void *)0) == t)
        return MEH_ERROR;
    if ((error = meh_update_hash(t, data, len)) != MEH_OK)
    {
        meh_destroy_hash(t);
        return error;
    }
    if ((error = meh_finish_hash(t, output)) != MEH_OK)
    {
        meh_destroy_hash(t);
        return error;
    }
    meh_destroy_hash(t);
    return MEH_OK;
}

canonical_original_code:
enum meh_error_t meh_hash(enum meh_hash_id hash_id, unsigned char *data, unsigned long len, unsigned char *output)
{
    enum meh_error_t error;
    struct meh_hash_s *t;
    t = meh_get_hash(hash_id);
    if (((void *)0) == t)
        return MEH_ERROR;
    if ((error = meh_update_hash(t, data, len)) != MEH_OK)
    {
        meh_destroy_hash(t);
        return error;
    }
    if ((error = meh_finish_hash(t, output)) != MEH_OK)
    {
        meh_destroy_hash(t);
        return error;
    }
    meh_destroy_hash(t);
    return MEH_OK;
}

variable_types: enum meh_hash_id { MEH_MD5=0, MEH_SHA1=1, MEH_SHA224=2, MEH_SHA256=3, MEH_SHA384=4, MEH_SHA512=5 }

variable_types:
data
unsigned char *

variable_types:
len
unsigned long

variable_types: enum meh_error_t { MEH_FILE_NOT_FOUND=-16, MEH_READ_ERROR=-15, MEH_WRITE_ERROR=-14, MEH_SOURCE_EXHAUSTED=-13, MEH_INVALID_PRNG=-12, MEH_INVALID_KDF=-11, MEH_INVALID_HASH=-10, MEH_INVALID_CIPHER=-9, MEH_INVALID_KEY_SIZE=-8, MEH_INVALID_IV_SIZE=-7, MEH_INVALID_ROUNDS=-6, MEH_INVALID_ARGUMENT=-5, MEH_OUT_OF_MEMORY=-4, MEH_BUFFER_UNDERFLOW=-3, MEH_BUFFER_OVERFLOW=-2, MEH_ERROR=-1, MEH_OK=0 }


original_code:
meh_error_t meh_reset_pbkdf2(MehPBKDF2 kdf,
                             const unsigned char* password, size_t pass_len,
                             const unsigned char* salt, size_t salt_len,
                             unsigned int iterations)
{
    if (((void *)0) == password || ((void *)0) == salt)
        return meh_error("invalid argument passed to meh_reset_pbkdf2",
                         MEH_INVALID_ARGUMENT);
    if (((void *)0) == kdf->password)
        kdf->password = malloc(pass_len);
    else if (kdf->pass_len < pass_len)
        kdf->password = realloc(kdf->password, pass_len);
    if (((void *)0) == kdf->password)
        return MEH_OUT_OF_MEMORY;
    kdf->pass_len = pass_len;
    memcpy(kdf->password, password, pass_len);
    if (((void *)0) == kdf->salt)
    {
        kdf->salt = malloc(salt_len);
        kdf->salt_len = salt_len;
    }
    else
        if (kdf->salt_len < salt_len)
            kdf->salt = realloc(kdf->salt, salt_len);
    if (((void *)0) == kdf->salt)
    {
        free(kdf->password);
        return MEH_OUT_OF_MEMORY;
    }
    memcpy(kdf->salt, salt, salt_len);
    kdf->iterations = iterations;
    kdf->index = kdf->hmac->output_size;
    memset(kdf->block_count, 0, sizeof (uint32_t));
    return meh_reset_hmac(kdf->hmac, kdf->password, kdf->pass_len);
}

canonical_original_code:
enum meh_error_t meh_reset_pbkdf2(struct meh_pbkdf2_state_s *kdf, unsigned char *password, unsigned long pass_len, unsigned char *salt, unsigned long salt_len, unsigned int iterations)
{
    if (((void *)0) == password || ((void *)0) == salt)
        return meh_error("invalid argument passed to meh_reset_pbkdf2",
                         MEH_INVALID_ARGUMENT);
    if (((void *)0) == kdf->password)
        kdf->password = malloc(pass_len);
    else if (kdf->pass_len < pass_len)
        kdf->password = realloc(kdf->password, pass_len);
    if (((void *)0) == kdf->password)
        return MEH_OUT_OF_MEMORY;
    kdf->pass_len = pass_len;
    memcpy(kdf->password, password, pass_len);
    if (((void *)0) == kdf->salt)
    {
        kdf->salt = malloc(salt_len);
        kdf->salt_len = salt_len;
    }
    else
        if (kdf->salt_len < salt_len)
            kdf->salt = realloc(kdf->salt, salt_len);
    if (((void *)0) == kdf->salt)
    {
        free(kdf->password);
        return MEH_OUT_OF_MEMORY;
    }
    memcpy(kdf->salt, salt, salt_len);
    kdf->iterations = iterations;
    kdf->index = kdf->hmac->output_size;
    memset(kdf->block_count, 0, sizeof (unsigned int));
    return meh_reset_hmac(kdf->hmac, kdf->password, kdf->pass_len);
}

variable_types: struct meh_pbkdf2_state_s { struct meh_hmac_s { struct meh_hash_s { union meh_hash_state_u { struct meh_md5_state_s { unsigned int total[2]; unsigned char buffer[64]; } *md5; struct meh_sha1_state_s { unsigned int total[2]; unsigned char buffer[64]; } *sha1; struct meh_sha256_state_s { unsigned int total[2]; unsigned char buffer[64]; } *sha256; struct meh_sha256_state_s *sha224; struct meh_sha512_state_s { unsigned int total[2]; unsigned long state[8]; unsigned char buffer[128]; } *sha384; struct meh_sha512_state_s *sha512; } state; enum meh_hash_id { MEH_MD5=0, MEH_SHA1=1, MEH_SHA224=2, MEH_SHA256=3, MEH_SHA384=4, MEH_SHA512=5 } id; unsigned long output_size; } *inner; unsigned char *opad; unsigned long output_size; enum meh_hash_id { MEH_MD5=0, MEH_SHA1=1, MEH_SHA224=2, MEH_SHA256=3, MEH_SHA384=4, MEH_SHA512=5 } id; } *hmac; unsigned char *salt; unsigned long salt_len; unsigned char *buffer; unsigned char block_count[4]; int iterations; } *

variable_types:
password
unsigned char *

variable_types:
salt
unsigned char *

variable_types:
iterations
unsigned int

return_type: enum meh_error_t { MEH_FILE_NOT_FOUND=-16, MEH_READ_ERROR=-15, MEH_WRITE_ERROR=-14, MEH_SOURCE_EXHAUSTED=-13, MEH_INVALID_PRNG=-12, MEH_INVALID_KDF=-11, MEH_INVALID_HASH=-10, MEH_INVALID_CIPHER=-9, MEH_INVALID_KEY_SIZE=-8, MEH_INVALID_IV_SIZE=-7, MEH_INVALID_ROUNDS=-6, MEH_INVALID_ARGUMENT=-5, MEH_OUT_OF_MEMORY=-4, MEH_BUFFER_UNDERFLOW=-3, MEH_BUFFER_OVERFLOW=-2, MEH_ERROR=-1, MEH_OK=0 }

user_defined_types: struct meh_pbkdf2_state_s { struct meh_hmac_s *hmac; unsigned char *salt; unsigned long salt_len; unsigned char *buffer; unsigned char block_count[4]; int iterations; }

user_defined_types: struct meh_hmac_s { struct meh_hash_s *inner; unsigned char *opad; unsigned long output_size; enum meh_hash_id id; }


original_code:
meh_error_t meh_update_pbkdf2(MehPBKDF2 kdf, unsigned char* output,
                              size_t want_len, size_t* get_len)
{
    meh_error_t error;
    int i, j, k;
    *get_len = 0;
    error = MEH_OK;
    for (i = 0; i < want_len; i++)
    {
        if (kdf->index == kdf->hmac->output_size)
        {
            _increment_counter(kdf->block_count, sizeof (uint32_t));
            if (0 == (((uint32_t)((kdf->block_count)[(0)]) << 24) | ((uint32_t)((kdf->block_count)[(0)+1]) << 16) | ((uint32_t)((kdf->block_count)[(0)+2]) << 8) | ((uint32_t)((kdf->block_count)[(0)+3]) )))
            {
                memset(kdf->block_count, 0xff, sizeof (uint32_t));
                return meh_error("source exhausted in meh_update_pbkdf2",
                                 MEH_SOURCE_EXHAUSTED);
            }
            memset(kdf->buffer, 0, kdf->hmac->output_size);
            for (j = 0; j < kdf->iterations; j++)
            {
                error = meh_reset_hmac(kdf->hmac, kdf->password, kdf->pass_len);
                if (0 != j)
                    error = meh_update_hmac(kdf->hmac, kdf->tmp, kdf->hmac->output_size);
                else
                {
                    error = meh_update_hmac(kdf->hmac, kdf->salt, kdf->salt_len);
                    error = meh_update_hmac(kdf->hmac,
                                            kdf->block_count, sizeof (uint32_t));
                }
                error = meh_finish_hmac(kdf->hmac, kdf->tmp);
                for (k = 0; k < kdf->hmac->output_size; k++)
                    kdf->buffer[k] ^= kdf->tmp[k];
            }
            kdf->index = 0;
        }
        output[i] = kdf->buffer[kdf->index++];
        (*get_len)++;
    }
    return error;
}

canonical_original_code:
enum meh_error_t meh_update_pbkdf2(struct meh_pbkdf2_state_s *kdf, unsigned char *output, unsigned long want_len, unsigned long *get_len)
{
    enum meh_error_t error;
    int i; int j; int k;
    *get_len = 0;
    error = MEH_OK;
    for (i = 0; i < want_len; i++)
    {
        if (kdf->index == kdf->hmac->output_size)
        {
            _increment_counter(kdf->block_count, sizeof (unsigned int));
            if (0 == (((unsigned int)((kdf->block_count)[(0)]) << 24) | ((unsigned int)((kdf->block_count)[(0)+1]) << 16) | ((unsigned int)((kdf->block_count)[(0)+2]) << 8) | ((unsigned int)((kdf->block_count)[(0)+3]) )))
            {
                memset(kdf->block_count, 0xff, sizeof (unsigned int));
                return meh_error("source exhausted in meh_update_pbkdf2",
                                 MEH_SOURCE_EXHAUSTED);
            }
            memset(kdf->buffer, 0, kdf->hmac->output_size);
            for (j = 0; j < kdf->iterations; j++)
            {
                error = meh_reset_hmac(kdf->hmac, kdf->password, kdf->pass_len);
                if (0 != j)
                    error = meh_update_hmac(kdf->hmac, kdf->tmp, kdf->hmac->output_size);
                else
                {
                    error = meh_update_hmac(kdf->hmac, kdf->salt, kdf->salt_len);
                    error = meh_update_hmac(kdf->hmac,
                                            kdf->block_count, sizeof (unsigned int));
                }
                error = meh_finish_hmac(kdf->hmac, kdf->tmp);
                for (k = 0; k < kdf->hmac->output_size; k++)
                    kdf->buffer[k] ^= kdf->tmp[k];
            }
            kdf->index = 0;
        }
        output[i] = kdf->buffer[kdf->index++];
        (*get_len)++;
    }
    return error;
}

variable_types: i int

variable_types: j int

variable_types: k int

user_defined_types: enum meh_error_t { MEH_FILE_NOT_FOUND=-16, MEH_READ_ERROR=-15, MEH_WRITE_ERROR=-14, MEH_SOURCE_EXHAUSTED=-13, MEH_INVALID_PRNG=-12, MEH_INVALID_KDF=-11, MEH_INVALID_HASH=-10, MEH_INVALID_CIPHER=-9, MEH_INVALID_KEY_SIZE=-8, MEH_INVALID_IV_SIZE=-7, MEH_INVALID_ROUNDS=-6, MEH_INVALID_ARGUMENT=-5, MEH_OUT_OF_MEMORY=-4, MEH_BUFFER_UNDERFLOW=-3, MEH_BUFFER_OVERFLOW=-2, MEH_ERROR=-1, MEH_OK=0 }


decompiled_code:
void __fastcall meh_destroy_pbkdf2(void *ptr)
{
if ( ptr )
{
meh_destroy_hmac(*(_QWORD *)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(ptr);
}
else
{
meh_warn("invalid argument passed to meh_destroy_pbkdf2");
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
meh_destroy_hmac(*(_QWORD *)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(ptr);
}
else
{
meh_warn("invalid argument passed to meh_destroy_pbkdf2");
}
}

original_code:
void meh_destroy_pbkdf2(MehPBKDF2 kdf)
{
    if (((void *)0) == kdf)
    {
        meh_warn("invalid argument passed to meh_destroy_pbkdf2");
        return;
    }
    meh_destroy_hmac(kdf->hmac);
    free(kdf->salt);
    free(kdf->password);
    free(kdf->buffer);
    free(kdf->tmp);
    free(kdf);
}

canonical_original_code:
void meh_destroy_pbkdf2(struct meh_pbkdf2_state_s *kdf)
{
    if (((void *)0) == kdf)
    {
        meh_warn("invalid argument passed to meh_destroy_pbkdf2");
        return;
    }
    meh_destroy_hmac(kdf->hmac);
    free(kdf->salt);
    free(kdf->password);
    free(kdf->buffer);
    free(kdf->tmp);
    free(kdf);
}


decompiled_code:
int __fastcall meh_warn(const char *a1)
{
return fprintf(stderr, "libmeh: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "libmeh: %s\n", a1);
}

original_code:
void meh_warn(const char* msg)
{
    fprintf(stderr, "libmeh: %s\n", msg);
}

canonical_original_code:
void meh_warn(char *msg)
{
    fprintf(stderr, "libmeh: %s\n", msg);
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall meh_error(const char *a1, unsigned int a2)
{
meh_warn(a1);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, unsigned int a2)
{
func0(a1);
return a2;
}

original_code:
meh_error_t meh_error(const char* msg, meh_error_t error)
{
    meh_warn(msg);
    return error;
}

canonical_original_code:
enum meh_error_t meh_error(char *msg, enum meh_error_t error)
{
    meh_warn(msg);
    return error;
}


shift

repo: thommey/plservices

decompiled_code:
unsigned __int64 __fastcall shift(unsigned __int8 *a1, int a2)
{
unsigned __int8 v2; // dl
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = *a1 + a2;
*a1 = v2;
if ( a2 > 0 )
{
memmove(&a1[16 * a2 + 8], a1 + 8, 16LL * v2);
}
else if ( a2 < 0 )
{
memmove(a1 + 8, &a1[-16 * a2 + 8], 16LL * v2);
}
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int8 *a1, int a2)
{
unsigned __int8 v2; // dl
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = *a1 + a2;
*a1 = v2;
if ( a2 > 0 )
{
memmove(&a1[16 * a2 + 8], a1 + 8, 16LL * v2);
}
else if ( a2 < 0 )
{
memmove(a1 + 8, &a1[-16 * a2 + 8], 16LL * v2);
}
return v4 - __readfsqword(0x28u);
}

original_code:
void shift(struct args *arg, int offset) {
 arg->c += offset;
 if (offset > 0)
  memmove(arg->v + offset, arg->v, arg->c * sizeof(*arg->v));
 else if (offset < 0) {
  offset = -offset;
  memmove(arg->v, arg->v + offset, arg->c * sizeof(*arg->v));
 }
}

variable_types: struct args { unsigned char c; struct funcarg { enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 } type; union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; } data; } v[20]; } *

variable_types: offset int

user_defined_types: struct args { unsigned char c; struct funcarg v[20]; }

user_defined_types: struct funcarg { enum argtype type; union argdata data; }


decompiled_code:
__int64 arg_int()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 1LL;
}

original_code:
struct funcarg arg_int(int i) {
 return (struct funcarg) {
  .type = ARGTYPE_INT, .data.i = i
 };
}

return_type: struct funcarg { enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 } type; union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; } data; }


decompiled_code:
__int64 arg_uint()
{
return 2LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 2LL;
}

original_code:
struct funcarg arg_uint(unsigned int u) {
 return (struct funcarg) {
  .type = ARGTYPE_UINT, .data.u = u
 };
}

variable_types:
u
unsigned int

user_defined_types: enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 }

user_defined_types: union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; }


decompiled_code:
__int64 arg_long()
{
return 3LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 3LL;
}

original_code:
struct funcarg arg_long(long l) {
 return (struct funcarg) {
  .type = ARGTYPE_LONG, .data.l = l
 };
}

variable_types: l long


decompiled_code:
__int64 arg_ulong()
{
return 4LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 4LL;
}

original_code:
struct funcarg arg_ulong(unsigned long ul) {
 return (struct funcarg) {
  .type = ARGTYPE_ULONG, .data.ul = ul
 };
}

variable_types:
ul
unsigned long


decompiled_code:
__int64 arg_time()
{
return 5LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 5LL;
}

original_code:
struct funcarg arg_time(time_t t) {
 return (struct funcarg) {
  .type = ARGTYPE_TIME, .data.t = t
 };
}

canonical_original_code:
struct funcarg arg_time(long t) {
 return (struct funcarg) {
  .type = ARGTYPE_TIME, .data.t = t
 };
}

variable_types: t long


decompiled_code:
__int64 arg_str()
{
return 9LL;
}

canonical_decompiled_code:
__int64 func9()
{
return 9LL;
}

original_code:
struct funcarg arg_str(char *s) {
 return (struct funcarg) {
  .type = ARGTYPE_STR, .data.p = s
 };
}

variable_types:
s
char *


decompiled_code:
__int64 arg_ptr()
{
return 10LL;
}

canonical_decompiled_code:
__int64 func10()
{
return 10LL;
}

original_code:
struct funcarg arg_ptr(void *p) {
 return (struct funcarg) {
  .type = ARGTYPE_PTR, .data.p = p
 };
}

variable_types:
p
void *


decompiled_code:
void *__fastcall pack_empty(void *a1)
{
memset(a1, 0, 0x148uLL);
return a1;
}

canonical_decompiled_code:
void *__fastcall func13(void *a1)
{
memset(a1, 0, 0x148uLL);
return a1;
}

original_code:
struct args pack_empty(void) {
 return (struct args) {
  .c = 0
 };
}

canonical_original_code:
struct args pack_empty() {
 return (struct args) {
  .c = 0
 };
}

return_type: struct args { unsigned char c; struct funcarg { enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 } type; union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; } data; } v[20]; }


decompiled_code:
__int64 __fastcall argdata_int(_DWORD *a1)
{
if ( *a1 != 1 )
_assert_fail("a->type == ARGTYPE_INT", "src/args.c", 0x90u, "argdata_int");
return (unsigned int)a1[2];
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1)
{
if ( *a1 != 1 )
_assert_fail("a->type == ARGTYPE_INT", "src/args.c", 0x90u, "argdata_int");
return (unsigned int)a1[2];
}

original_code:
int argdata_int(struct funcarg *a) {
 ((a->type == ARGTYPE_INT) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_INT", "src/args.c", 144, __extension__ __PRETTY_FUNCTION__));
 return a->data.i;
}

variable_types: struct funcarg { enum argtype { ARGTYPE_NONE=0, ARGTYPE_INT=1, ARGTYPE_UINT=2, ARGTYPE_LONG=3, ARGTYPE_ULONG=4, ARGTYPE_TIME=5, ARGTYPE_USER=6, ARGTYPE_CHAN=7, ARGTYPE_SERVER=8, ARGTYPE_STR=9, ARGTYPE_PTR=10 } type; union argdata { int i; unsigned int u; long l; unsigned long ul; long t; void *p; } data; } *

return_type: int


decompiled_code:
__int64 __fastcall argdata_uint(_DWORD *a1)
{
if ( *a1 != 2 )
_assert_fail("a->type == ARGTYPE_UINT", "src/args.c", 0x95u, "argdata_uint");
return (unsigned int)a1[2];
}

canonical_decompiled_code:
__int64 __fastcall func15(_DWORD *a1)
{
if ( *a1 != 2 )
_assert_fail("a->type == ARGTYPE_UINT", "src/args.c", 0x95u, "argdata_uint");
return (unsigned int)a1[2];
}

original_code:
unsigned int argdata_uint(struct funcarg *a) {
 ((a->type == ARGTYPE_UINT) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_UINT", "src/args.c", 149, __extension__ __PRETTY_FUNCTION__));
 return a->data.u;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall argdata_long(__int64 a1)
{
if ( *(_DWORD *)a1 != 3 )
_assert_fail("a->type == ARGTYPE_LONG", "src/args.c", 0x9Au, "argdata_long");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
if ( *(_DWORD *)a1 != 3 )
_assert_fail("a->type == ARGTYPE_LONG", "src/args.c", 0x9Au, "argdata_long");
return *(_QWORD *)(a1 + 8);
}

original_code:
long argdata_long(struct funcarg *a) {
 ((a->type == ARGTYPE_LONG) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_LONG", "src/args.c", 154, __extension__ __PRETTY_FUNCTION__));
 return a->data.l;
}

return_type: long


decompiled_code:
__int64 __fastcall argdata_time(__int64 a1)
{
if ( *(_DWORD *)a1 != 5 )
_assert_fail("a->type == ARGTYPE_TIME", "src/args.c", 0x9Fu, "argdata_time");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
if ( *(_DWORD *)a1 != 5 )
_assert_fail("a->type == ARGTYPE_TIME", "src/args.c", 0x9Fu, "argdata_time");
return *(_QWORD *)(a1 + 8);
}

original_code:
time_t argdata_time(struct funcarg *a) {
 ((a->type == ARGTYPE_TIME) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_TIME", "src/args.c", 159, __extension__ __PRETTY_FUNCTION__));
 return a->data.t;
}

canonical_original_code:
long argdata_time(struct funcarg *a) {
 ((a->type == ARGTYPE_TIME) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_TIME", "src/args.c", 159, __extension__ __PRETTY_FUNCTION__));
 return a->data.t;
}


decompiled_code:
__int64 __fastcall argdata_str(__int64 a1)
{
if ( *(_DWORD *)a1 != 9 )
_assert_fail("a->type == ARGTYPE_STR", "src/args.c", 0xB3u, "argdata_str");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
if ( *(_DWORD *)a1 != 9 )
_assert_fail("a->type == ARGTYPE_STR", "src/args.c", 0xB3u, "argdata_str");
return *(_QWORD *)(a1 + 8);
}

original_code:
char *argdata_str(struct funcarg *a) {
 ((a->type == ARGTYPE_STR) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_STR", "src/args.c", 179, __extension__ __PRETTY_FUNCTION__));
 return a->data.p;
}

return_type: char *


decompiled_code:
__int64 __fastcall argdata_ptr(__int64 a1)
{
if ( *(_DWORD *)a1 != 10 )
_assert_fail("a->type == ARGTYPE_PTR", "src/args.c", 0xB8u, "argdata_ptr");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
if ( *(_DWORD *)a1 != 10 )
_assert_fail("a->type == ARGTYPE_PTR", "src/args.c", 0xB8u, "argdata_ptr");
return *(_QWORD *)(a1 + 8);
}

original_code:
void *argdata_ptr(struct funcarg *a) {
 ((a->type == ARGTYPE_PTR) ? (void) (0) : __assert_fail ("a->type == ARGTYPE_PTR", "src/args.c", 184, __extension__ __PRETTY_FUNCTION__));
 return a->data.p;
}

return_type: void *


decompiled_code:
unsigned __int64 __fastcall convert_nick(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_user_by_nick(a2);
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = v2 != 0 ? 0xA : 0;
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_user_by_nick(a2);
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = v2 != 0 ? 0xA : 0;
return v4 - __readfsqword(0x28u);
}

original_code:
void convert_nick(struct funcarg *a, char *str) {
 a->data.p = get_user_by_nick(str);
 a->type = a->data.p ? ARGTYPE_PTR : ARGTYPE_NONE;
}

variable_types:
str
char *


decompiled_code:
unsigned __int64 __fastcall convert_unum(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_user_by_numericstr(a2);
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = v2 != 0 ? 0xA : 0;
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_user_by_numericstr(a2);
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = v2 != 0 ? 0xA : 0;
return v4 - __readfsqword(0x28u);
}

original_code:
void convert_unum(struct funcarg *a, char *str) {
 a->data.p = get_user_by_numericstr(str);
 a->type = a->data.p ? ARGTYPE_PTR : ARGTYPE_NONE;
}


decompiled_code:
unsigned __int64 __fastcall convert_snum(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_server_by_numericstr(a2);
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = v2 != 0 ? 0xA : 0;
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
v2 = get_server_by_numericstr(a2);
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = v2 != 0 ? 0xA : 0;
return v4 - __readfsqword(0x28u);
}

original_code:
void convert_snum(struct funcarg *a, char *str) {
 a->data.p = get_server_by_numericstr(str);
 a->type = a->data.p ? ARGTYPE_PTR : ARGTYPE_NONE;
}


decompiled_code:
unsigned __int64 __fastcall convert_num(__int64 a1, const char *a2)
{
size_t v2; // rax
int v3; // eax
unsigned __int64 v5; // [rsp+8h] [rbp-20h]

v5 = __readfsqword(0x28u);
v2 = strlen(a2);
if ( v2 == 2 )
{
*(_QWORD *)(a1 + 8) = get_server_by_numericstr(a2);
LABEL_5:
v3 = *(_QWORD *)(a1 + 8) != 0LL ? 0xA : 0;
goto LABEL_6;
}
if ( v2 == 5 )
{
*(_QWORD *)(a1 + 8) = get_user_by_numericstr(a2);
goto LABEL_5;
}
*(_QWORD *)(a1 + 8) = 0LL;
v3 = 0;
LABEL_6:
*(_DWORD *)a1 = v3;
return v5 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, const char *a2)
{
size_t v2; // rax
int v3; // eax
unsigned __int64 v5; // [rsp+8h] [rbp-20h]

v5 = __readfsqword(0x28u);
v2 = strlen(a2);
if ( v2 == 2 )
{
*(_QWORD *)(a1 + 8) = get_server_by_numericstr(a2);
LABEL_5:
v3 = *(_QWORD *)(a1 + 8) != 0LL ? 0xA : 0;
goto LABEL_6;
}
if ( v2 == 5 )
{
*(_QWORD *)(a1 + 8) = get_user_by_numericstr(a2);
goto LABEL_5;
}
*(_QWORD *)(a1 + 8) = 0LL;
v3 = 0;
LABEL_6:
*(_DWORD *)a1 = v3;
return v5 - __readfsqword(0x28u);
}

original_code:
void convert_num(struct funcarg *a, char *str) {
 if (strlen(str) == 2)
  a->data.p = get_server_by_numericstr(str);
 else if (strlen(str) == 5)
  a->data.p = get_user_by_numericstr(str);
 else
  a->data.p = ((void *)0);
 a->type = a->data.p ? ARGTYPE_PTR : ARGTYPE_NONE;
}


decompiled_code:
unsigned __int64 __fastcall convert_chan(__int64 a1, const char *a2)
{
int v2; // eax
__int64 v4; // rax
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

v5 = __readfsqword(0x28u);
if ( !strcmp(a2, "0") )
{
*(_QWORD *)(a1 + 8) = &chan0_0;
v2 = 10;
}
else
{
v4 = get_channel_by_name(a2);
*(_QWORD *)(a1 + 8) = v4;
v2 = v4 != 0 ? 0xA : 0;
}
*(_DWORD *)a1 = v2;
return v5 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(__int64 a1, const char *a2)
{
int v2; // eax
__int64 v4; // rax
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

v5 = __readfsqword(0x28u);
if ( !strcmp(a2, "0") )
{
*(_QWORD *)(a1 + 8) = &chan0_0;
v2 = 10;
}
else
{
v4 = get_channel_by_name(a2);
*(_QWORD *)(a1 + 8) = v4;
v2 = v4 != 0 ? 0xA : 0;
}
*(_DWORD *)a1 = v2;
return v5 - __readfsqword(0x28u);
}

original_code:
void convert_chan(struct funcarg *a, char *str) {
 static struct channel chan0 = { 0x38B7 };
 a->data.p = !strcmp(str, "0") ? &chan0 : get_channel_by_name(str);
 a->type = a->data.p ? ARGTYPE_PTR : ARGTYPE_NONE;
}

variable_types: struct channel { unsigned int magic; char name[-1]; char key[-1]; char topic[-1]; long limit; long ts; int usercount; unsigned long mode; struct jtableP { void *t; } ops; struct jtableS { void *t; } bans; }

user_defined_types: struct channel { unsigned int magic; char name[-1]; char key[-1]; char topic[-1]; long limit; long ts; int usercount; unsigned long mode; struct jtableP ops; struct jtableS bans; }


decompiled_code:
unsigned __int64 __fastcall convert_uint(_DWORD *a1, const char *a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*a1 = 0;
if ( *a2 )
{
a1[2] = strtoul(a2, &v3, 10);
if ( !*v3 )
*a1 = 2;
}
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(_DWORD *a1, const char *a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*a1 = 0;
if ( *a2 )
{
a1[2] = strtoul(a2, &v3, 10);
if ( !*v3 )
*a1 = 2;
}
return v4 - __readfsqword(0x28u);
}

original_code:
void convert_uint(struct funcarg *a, char *str) {
 char *endptr;
 a->type = ARGTYPE_NONE;
 if (!str[0])
  return;
 a->data.u = (unsigned int)strtoul(str, &endptr, 10);
 if (*endptr != '\0')
  return;
 a->type = ARGTYPE_UINT;
}

variable_types:
endptr
char *


decompiled_code:
unsigned __int64 __fastcall convert_long(__int64 a1, const char *a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*(_DWORD *)a1 = 0;
if ( *a2 )
{
*(_QWORD *)(a1 + 8) = strtol(a2, &v3, 10);
if ( !*v3 )
*(_DWORD *)a1 = 3;
}
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1, const char *a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*(_DWORD *)a1 = 0;
if ( *a2 )
{
*(_QWORD *)(a1 + 8) = strtol(a2, &v3, 10);
if ( !*v3 )
*(_DWORD *)a1 = 3;
}
return v4 - __readfsqword(0x28u);
}

original_code:
void convert_long(struct funcarg *a, char *str) {
 char *endptr;
 a->type = ARGTYPE_NONE;
 if (!str[0])
  return;
 a->data.l = strtol(str, &endptr, 10);
 if (*endptr != '\0')
  return;
 a->type = ARGTYPE_LONG;
}


decompiled_code:
unsigned __int64 __fastcall convert_time(__int64 a1, const char *a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*(_DWORD *)a1 = 0;
if ( *a2 )
{
*(_QWORD *)(a1 + 8) = strtoull(a2, &v3, 10);
if ( !*v3 )
*(_DWORD *)a1 = 5;
}
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(__int64 a1, const char *a2)
{
char *v3; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*(_DWORD *)a1 = 0;
if ( *a2 )
{
*(_QWORD *)(a1 + 8) = strtoull(a2, &v3, 10);
if ( !*v3 )
*(_DWORD *)a1 = 5;
}
return v4 - __readfsqword(0x28u);
}

original_code:
void convert_time(struct funcarg *a, char *str) {
 char *endptr;
 a->type = ARGTYPE_NONE;
 if (!str[0])
  return;
 a->data.t = strtoull(str, &endptr, 10);
 if (*endptr != '\0')
  return;
 a->type = ARGTYPE_TIME;
}


decompiled_code:
unsigned __int64 __fastcall print_key_value(const char *a1, const char *a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
logfmt(0x4000LL, "%s = %s\n", a1, a2);
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(const char *a1, const char *a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
logfmt(0x4000LL, "%s = %s\n", a1, a2);
return v3 - __readfsqword(0x28u);
}

original_code:
static void print_key_value(char *key, char *value, char *section) {
 logfmt(0x4000, "%s = %s" "\n", key, value);
}

variable_types:
key
char *

variable_types:
value
char *

variable_types:
section
char *


skip

decompiled_code:
unsigned __int64 __fastcall skip(const char **a1, const char *a2)
{
const char *v2; // rbx
unsigned __int64 v4; // [rsp+8h] [rbp-20h]

v4 = __readfsqword(0x28u);
if ( *a1 )
{
v2 = *a1;
*a1 = &v2[strspn(*a1, a2)];
}
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(const char **a1, const char *a2)
{
const char *v2; // rbx
unsigned __int64 v4; // [rsp+8h] [rbp-20h]

v4 = __readfsqword(0x28u);
if ( *a1 )
{
v2 = *a1;
*a1 = &v2[strspn(*a1, a2)];
}
return v4 - __readfsqword(0x28u);
}

original_code:
static void skip(char **str, char *delim) {
 if (!*str)
  return;
 *str += strspn(*str, delim);
}

variable_types:
str
char **

variable_types:
delim
char *


decompiled_code:
unsigned __int64 __fastcall print_section(const char *a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-20h] BYREF
unsigned __int64 v4; // [rsp+18h] [rbp-10h]

v3 = a2;
v4 = __readfsqword(0x28u);
logfmt(0x4000LL, "[%s]\n", a1);
jtableS_iterate(&v3, print_key_value, a1);
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(const char *a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-20h] BYREF
unsigned __int64 v4; // [rsp+18h] [rbp-10h]

v3 = a2;
v4 = __readfsqword(0x28u);
logfmt(0x4000LL, "[%s]\n", a1);
jtableS_iterate(&v3, print_key_value, a1);
return v4 - __readfsqword(0x28u);
}

original_code:
static void print_section(char *section, jtableS sectiondata) {
 logfmt(0x4000, "[%s]" "\n", section);
 jtableS_iterate(&sectiondata, (jtableS_cb)print_key_value, section);
}

canonical_original_code:
static void print_section(char *section, struct jtableS sectiondata) {
 logfmt(0x4000, "[%s]" "\n", section);
 jtableS_iterate(&sectiondata, (void (*)(char *key, void *data, void *param))print_key_value, section);
}

variable_types:
sectiondata
struct jtableS { void *t; }


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

if ( a1 && a2 && *a1 && *a2 )
{
result = jtableS_getptr(&configdata, a1);
if ( result )
result = jtableS_get(result, a2);
}
else
{
logtxt(256LL, "Invalid config file get with empty data\n");
result = 0LL;
}
return result;
}

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

if ( a1 && a2 && *a1 && *a2 )
{
result = jtableS_getptr(&configdata, a1);
if ( result )
result = jtableS_get(result, a2);
}
else
{
logtxt(256LL, "Invalid config file get with empty data\n");
result = 0LL;
}
return result;
}

original_code:
char *config_get(const char *section, const char *key) {
 jtableS *sectiondata;
 if (!section || !key || !section[0] || !key[0]) {
  logtxt(0x0100, "Invalid config file get with empty data" "\n");
  return ((void *)0);
 }
 sectiondata = jtableS_getptr(&configdata, section);
 if (!sectiondata)
  return ((void *)0);
 return jtableS_get(sectiondata, key);
}

canonical_original_code:
char *config_get(char *section, char *key) {
 struct jtableS *sectiondata;
 if (!section || !key || !section[0] || !key[0]) {
  logtxt(0x0100, "Invalid config file get with empty data" "\n");
  return ((void *)0);
 }
 sectiondata = jtableS_getptr(&configdata, section);
 if (!sectiondata)
  return ((void *)0);
 return jtableS_get(sectiondata, key);
}

variable_types:
sectiondata
struct jtableS { void *t; } *


decompiled_code:
unsigned __int64 __fastcall config_set(_BYTE *a1, _BYTE *a2, _BYTE *a3)
{
__int64 v5; // r13
__int64 v6; // rax
__int64 v7; // rax
unsigned __int64 v8; // [rsp+8h] [rbp-30h]

v8 = __readfsqword(0x28u);
if ( a3 != 0LL && a2 != 0LL && a1 && *a1 && *a2 && *a3 )
{
v5 = jtableS_getptr(&configdata, a1);
if ( !v5 )
{
jtableS_insert(&configdata, a1, 0LL);
v5 = jtableS_getptr(&configdata, a1);
}
v6 = jtableS_get(v5, a2);
sfree(v6);
v7 = sstrdup(a3);
jtableS_insert(v5, a2, v7);
}
else
{
logtxt(256LL, "Invalid config file insert with empty data\n");
}
return v8 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(_BYTE *a1, _BYTE *a2, _BYTE *a3)
{
__int64 v5; // r13
__int64 v6; // rax
__int64 v7; // rax
unsigned __int64 v8; // [rsp+8h] [rbp-30h]

v8 = __readfsqword(0x28u);
if ( a3 != 0LL && a2 != 0LL && a1 && *a1 && *a2 && *a3 )
{
v5 = jtableS_getptr(&configdata, a1);
if ( !v5 )
{
jtableS_insert(&configdata, a1, 0LL);
v5 = jtableS_getptr(&configdata, a1);
}
v6 = jtableS_get(v5, a2);
sfree(v6);
v7 = sstrdup(a3);
jtableS_insert(v5, a2, v7);
}
else
{
logtxt(256LL, "Invalid config file insert with empty data\n");
}
return v8 - __readfsqword(0x28u);
}

original_code:
void config_set(const char *section, const char *key, const char *value) {
 jtableS *sectiondata;
 char *tmp;
 if (!section || !key || !value || !section[0] || !key[0] || !value[0]) {
  logtxt(0x0100, "Invalid config file insert with empty data" "\n");
  return;
 }
 sectiondata = jtableS_getptr(&configdata, section);
 if (!sectiondata) {
  jtableS_insert(&configdata, section, ((void *)0));
  sectiondata = jtableS_getptr(&configdata, section);
 }
 tmp = jtableS_get(sectiondata, key);
 sfree(tmp);
 jtableS_insert(sectiondata, key, sstrdup(value));
}

canonical_original_code:
void config_set(char *section, char *key, char *value) {
 struct jtableS *sectiondata;
 char *tmp;
 if (!section || !key || !value || !section[0] || !key[0] || !value[0]) {
  logtxt(0x0100, "Invalid config file insert with empty data" "\n");
  return;
 }
 sectiondata = jtableS_getptr(&configdata, section);
 if (!sectiondata) {
  jtableS_insert(&configdata, section, ((void *)0));
  sectiondata = jtableS_getptr(&configdata, section);
 }
 tmp = jtableS_get(sectiondata, key);
 sfree(tmp);
 jtableS_insert(sectiondata, key, sstrdup(value));
}

variable_types:
tmp
char *


decompiled_code:
unsigned __int64 print_config()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
jtableS_iterate(&configdata, print_section, 0LL);
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func8()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
jtableS_iterate(&configdata, print_section, 0LL);
return v1 - __readfsqword(0x28u);
}

original_code:
void print_config(void) {
 jtableS_iterate(&configdata, (jtableS_cb)print_section, ((void *)0));
}

canonical_original_code:
void print_config() {
 jtableS_iterate(&configdata, (void (*)(char *key, void *data, void *param))print_section, ((void *)0));
}


decompiled_code:
__int64 __fastcall get_user_by_numeric(__int64 a1)
{
return jtableL_get(&userlist_num, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return jtableL_get(&userlist_num, a1);
}

original_code:
struct user *get_user_by_numeric(unsigned long numeric) {
 return jtableL_get(&userlist_num, numeric);
}

variable_types:
numeric
unsigned long

return_type: struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP { void *t; } channels; struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP users; unsigned long mode; } *server; } *

user_defined_types: struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP channels; struct server *server; }


decompiled_code:
__int64 get_user_by_numericstr()
{
__int64 v0; // rax

v0 = str2unum();
return get_user_by_numeric(v0);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax

v0 = str2unum();
return func0(v0);
}

original_code:
struct user *get_user_by_numericstr(const char *numeric) {
 return get_user_by_numeric(str2unum(numeric));
}

canonical_original_code:
struct user *get_user_by_numericstr(char *numeric) {
 return get_user_by_numeric(str2unum(numeric));
}

variable_types:
numeric
char *

user_defined_types: struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP users; unsigned long mode; }


decompiled_code:
__int64 __fastcall get_user_by_nick(__int64 a1)
{
__int64 v1; // rax
_QWORD v3[5]; // [rsp+0h] [rbp-28h] BYREF

v3[3] = __readfsqword(0x28u);
v1 = strconv(&rfc_tolower, v3, 16LL, a1);
return jtableS_get(&userlist_nick, v1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
_QWORD v3[5]; // [rsp+0h] [rbp-28h] BYREF

v3[3] = __readfsqword(0x28u);
v1 = strconv(&rfc_tolower, v3, 16LL, a1);
return jtableS_get(&userlist_nick, v1);
}

original_code:
struct user *get_user_by_nick(const char *nick) {
 char buf[15 +1];
 return jtableS_get(&userlist_nick, strconv(rfc_tolower, buf, sizeof(buf), nick));
}

canonical_original_code:
struct user *get_user_by_nick(char *nick) {
 char buf[-1];
 return jtableS_get(&userlist_nick, strconv(rfc_tolower, buf, sizeof(buf), nick));
}

variable_types:
nick
char *

variable_types:
buf
char [-1]


decompiled_code:
__int64 __fastcall add_user(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v9; // rbx
__int64 v10; // rax
__int64 v11; // rbp
__int64 v12; // rax
char v15[24]; // [rsp+10h] [rbp-58h] BYREF
unsigned __int64 v16; // [rsp+28h] [rbp-40h]

v16 = __readfsqword(0x28u);
v9 = zmalloc(504LL);
*(_DWORD *)v9 = 18929;
strncpyz(v9 + 16, a1, 6LL);
*(_QWORD *)(v9 + 8) = str2unum(a1);
*(_DWORD *)(v9 + 300) = a2;
strncpyz(v9 + 22, a3, 16LL);
strncpyz(v9 + 38, a4, 11LL);
strncpyz(v9 + 49, a5, 64LL);
strncpyz(v9 + 248, a6, 51LL);
v10 = get_server_by_numericstr(a1);
if ( !v10 )
_assert_fail("s", "src/users.c", 0x43u, "add_user");
v11 = v10;
server_add_user(v10, v9);
*(_QWORD *)(v9 + 496) = v11;
v12 = strconv(&rfc_tolower, v15, 16LL, a3);
jtableS_insert(&userlist_nick, v12, v9);
return jtableL_insert(&userlist_num, *(_QWORD *)(v9 + 8), v9);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v9; // rbx
__int64 v10; // rax
__int64 v11; // rbp
__int64 v12; // rax
char v15[24]; // [rsp+10h] [rbp-58h] BYREF
unsigned __int64 v16; // [rsp+28h] [rbp-40h]

v16 = __readfsqword(0x28u);
v9 = zmalloc(504LL);
*(_DWORD *)v9 = 18929;
strncpyz(v9 + 16, a1, 6LL);
*(_QWORD *)(v9 + 8) = str2unum(a1);
*(_DWORD *)(v9 + 300) = a2;
strncpyz(v9 + 22, a3, 16LL);
strncpyz(v9 + 38, a4, 11LL);
strncpyz(v9 + 49, a5, 64LL);
strncpyz(v9 + 248, a6, 51LL);
v10 = get_server_by_numericstr(a1);
if ( !v10 )
_assert_fail("s", "src/users.c", 0x43u, "add_user");
v11 = v10;
server_add_user(v10, v9);
*(_QWORD *)(v9 + 496) = v11;
v12 = strconv(&rfc_tolower, v15, 16LL, a3);
jtableS_insert(&userlist_nick, v12, v9);
return jtableL_insert(&userlist_num, *(_QWORD *)(v9 + 8), v9);
}

original_code:
struct user *add_user(char *numeric, int hops, char *nick, const char *user, const char *host, const char *realname) {
 char buf[15 +1];
 struct user *u;
 struct server *s;
 u = zmalloc(sizeof(*u));
 u->magic = 0x49F1;
 strncpyz((u->numericstr), (numeric), sizeof(u->numericstr));
 u->numeric = str2unum(numeric);
 u->hops = hops;
 strncpyz((u->nick), (nick), sizeof(u->nick));
 strncpyz((u->user), (user), sizeof(u->user));
 strncpyz((u->host), (host), sizeof(u->host));
 strncpyz((u->realname), (realname), sizeof(u->realname));
 s = get_server_by_numericstr(numeric);
 ((s) ? (void) (0) : __assert_fail ("s", "src/users.c", 67, __extension__ __PRETTY_FUNCTION__));
 server_add_user(s, u);
 u->server = s;
 jtableS_insert(&userlist_nick, strconv(rfc_tolower, buf, sizeof(buf), nick), u);
 return jtableL_insert(&userlist_num, u->numeric, u);
}

canonical_original_code:
struct user *add_user(char *numeric, int hops, char *nick, char *user, char *host, char *realname) {
 char buf[-1];
 struct user *u;
 struct server *s;
 u = zmalloc(sizeof(*u));
 u->magic = 0x49F1;
 strncpyz((u->numericstr), (numeric), sizeof(u->numericstr));
 u->numeric = str2unum(numeric);
 u->hops = hops;
 strncpyz((u->nick), (nick), sizeof(u->nick));
 strncpyz((u->user), (user), sizeof(u->user));
 strncpyz((u->host), (host), sizeof(u->host));
 strncpyz((u->realname), (realname), sizeof(u->realname));
 s = get_server_by_numericstr(numeric);
 ((s) ? (void) (0) : __assert_fail ("s", "src/users.c", 67, __extension__ __PRETTY_FUNCTION__));
 server_add_user(s, u);
 u->server = s;
 jtableS_insert(&userlist_nick, strconv(rfc_tolower, buf, sizeof(buf), nick), u);
 return jtableL_insert(&userlist_num, u->numeric, u);
}

variable_types: hops int

variable_types:
user
char *

variable_types:
host
char *

variable_types:
realname
char *

variable_types: struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP { void *t; } channels; struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP users; unsigned long mode; } *server; } *

variable_types: struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP { void *t; } users; unsigned long mode; } *


decompiled_code:
unsigned __int64 __fastcall del_user(void *ptr)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rax
_BYTE v5[328]; // [rsp-150h] [rbp-2D8h] BYREF
_BYTE v6[336]; // [rsp+0h] [rbp-188h] BYREF
char v7[24]; // [rsp+150h] [rbp-38h] BYREF
unsigned __int64 v8; // [rsp+168h] [rbp-20h]

v8 = __readfsqword(0x28u);
v1 = arg_ptr();
pack_args(v6, v1, v2, 0LL, 0LL);
qmemcpy(v5, v6, sizeof(v5));
hook_call("onuserdel");
server_del_user(*((_QWORD *)ptr + 62), ptr);
v3 = strconv(&rfc_tolower, v7, 16LL, (char *)ptr + 22);
jtableS_remove(&userlist_nick, v3);
jtableL_remove(&userlist_num, *((_QWORD *)ptr + 1));
jtableP_unset(&opers, ptr);
free(ptr);
return v8 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(void *ptr)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rax
_BYTE v5[328]; // [rsp-150h] [rbp-2D8h] BYREF
_BYTE v6[336]; // [rsp+0h] [rbp-188h] BYREF
char v7[24]; // [rsp+150h] [rbp-38h] BYREF
unsigned __int64 v8; // [rsp+168h] [rbp-20h]

v8 = __readfsqword(0x28u);
v1 = arg_ptr();
pack_args(v6, v1, v2, 0LL, 0LL);
qmemcpy(v5, v6, sizeof(v5));
hook_call("onuserdel");
server_del_user(*((_QWORD *)ptr + 62), ptr);
v3 = strconv(&rfc_tolower, v7, 16LL, (char *)ptr + 22);
jtableS_remove(&userlist_nick, v3);
jtableL_remove(&userlist_num, *((_QWORD *)ptr + 1));
jtableP_unset(&opers, ptr);
free(ptr);
return v8 - __readfsqword(0x28u);
}

original_code:
void del_user(struct user *user) {
 char buf[15 +1];
 hook_call("onuserdel", pack_args(arg_ptr(user), (struct funcarg) {.type = ARGTYPE_NONE}));
 server_del_user(user->server, user);
 jtableS_remove(&userlist_nick, strconv(rfc_tolower, buf, sizeof(buf), user->nick));
 jtableL_remove(&userlist_num, user->numeric);
 jtableP_unset(&opers, user);
 free(user);
}

canonical_original_code:
void del_user(struct user *user) {
 char buf[-1];
 hook_call("onuserdel", pack_args(arg_ptr(user), (struct funcarg) {.type = ARGTYPE_NONE}));
 server_del_user(user->server, user);
 jtableS_remove(&userlist_nick, strconv(rfc_tolower, buf, sizeof(buf), user->nick));
 jtableL_remove(&userlist_num, user->numeric);
 jtableP_unset(&opers, user);
 free(user);
}


decompiled_code:
unsigned __int64 __fastcall del_user_iter(_DWORD *a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
if ( a1 && *a1 == 18929 )
del_user(a1);
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(_DWORD *a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
if ( a1 && *a1 == 18929 )
func4(a1);
return v2 - __readfsqword(0x28u);
}

original_code:
void del_user_iter(void *uptr, void *unused) {
 if (!uptr || !(((struct entity *)(uptr))->magic == 0x49F1))
  return;
 del_user(uptr);
}

variable_types:
uptr
void *

variable_types:
unused
void *


decompiled_code:
unsigned __int64 __fastcall user_nickchange(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rax
_BYTE v5[24]; // [rsp+0h] [rbp-48h] BYREF
unsigned __int64 v6; // [rsp+18h] [rbp-30h]

v6 = __readfsqword(0x28u);
v2 = strconv(&rfc_tolower, v5, 16LL, a1 + 22);
jtableS_remove(&userlist_nick, v2);
v3 = strconv(&rfc_tolower, v5, 16LL, a2);
jtableS_insert(&userlist_nick, v3, a1);
strncpyz(a1 + 22, a2, 16LL);
return v6 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rax
_BYTE v5[24]; // [rsp+0h] [rbp-48h] BYREF
unsigned __int64 v6; // [rsp+18h] [rbp-30h]

v6 = __readfsqword(0x28u);
v2 = strconv(&rfc_tolower, v5, 16LL, a1 + 22);
jtableS_remove(&userlist_nick, v2);
v3 = strconv(&rfc_tolower, v5, 16LL, a2);
jtableS_insert(&userlist_nick, v3, a1);
strncpyz(a1 + 22, a2, 16LL);
return v6 - __readfsqword(0x28u);
}

original_code:
void user_nickchange(struct user *u, char *newnick) {
 char buf[15 +1];
 jtableS_remove(&userlist_nick, strconv(rfc_tolower, buf, sizeof(buf), u->nick));
 jtableS_insert(&userlist_nick, strconv(rfc_tolower, buf, sizeof(buf), newnick), u);
 strncpyz((u->nick), (newnick), sizeof(u->nick));
}

canonical_original_code:
void user_nickchange(struct user *u, char *newnick) {
 char buf[-1];
 jtableS_remove(&userlist_nick, strconv(rfc_tolower, buf, sizeof(buf), u->nick));
 jtableS_insert(&userlist_nick, strconv(rfc_tolower, buf, sizeof(buf), newnick), u);
 strncpyz((u->nick), (newnick), sizeof(u->nick));
}

variable_types:
newnick
char *


decompiled_code:
unsigned __int64 __fastcall user_setopername(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
if ( a2 )
strncpyz(a1 + 188, a2, 16LL);
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
if ( a2 )
strncpyz(a1 + 188, a2, 16LL);
return v3 - __readfsqword(0x28u);
}

original_code: void user_setopername (struct user *u, char *str) { if (str) strncpyz((u->opername), (str), sizeof(u->opername)); }

canonical_original_code: void user_setopername(struct user *u, char *str) { if (str) strncpyz((u->opername), (str), sizeof(u->opername)); }

variable_types:
str
char *


decompiled_code:
unsigned __int64 __fastcall user_unsetopername(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
*(_BYTE *)(a1 + 188) = 0;
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
*(_BYTE *)(a1 + 188) = 0;
return v2 - __readfsqword(0x28u);
}

original_code: void user_unsetopername (struct user *u) { *u->opername = '\0'; }

canonical_original_code: void user_unsetopername(struct user *u) { *u->opername = '\0'; }


decompiled_code:
unsigned __int64 __fastcall user_setfakehost(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
if ( a2 )
strncpyz(a1 + 113, a2, 75LL);
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
if ( a2 )
strncpyz(a1 + 113, a2, 75LL);
return v3 - __readfsqword(0x28u);
}

original_code: void user_setfakehost (struct user *u, char *str) { if (str) strncpyz((u->fakehost), (str), sizeof(u->fakehost)); }

canonical_original_code: void user_setfakehost(struct user *u, char *str) { if (str) strncpyz((u->fakehost), (str), sizeof(u->fakehost)); }


decompiled_code:
unsigned __int64 __fastcall user_unsetfakehost(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
*(_BYTE *)(a1 + 113) = 0;
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
*(_BYTE *)(a1 + 113) = 0;
return v2 - __readfsqword(0x28u);
}

original_code: void user_unsetfakehost (struct user *u) { *u->fakehost = '\0'; }

canonical_original_code: void user_unsetfakehost(struct user *u) { *u->fakehost = '\0'; }


decompiled_code:
unsigned __int64 __fastcall user_setawaymsg(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
if ( a2 )
strncpyz(a1 + 308, a2, 161LL);
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(__int64 a1, __int64 a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
if ( a2 )
strncpyz(a1 + 308, a2, 161LL);
return v3 - __readfsqword(0x28u);
}

original_code: void user_setawaymsg (struct user *u, char *str) { if (str) strncpyz((u->awaymsg), (str), sizeof(u->awaymsg)); }

canonical_original_code: void user_setawaymsg(struct user *u, char *str) { if (str) strncpyz((u->awaymsg), (str), sizeof(u->awaymsg)); }


decompiled_code:
unsigned __int64 __fastcall user_unsetawaymsg(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
*(_BYTE *)(a1 + 308) = 0;
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func12(__int64 a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
*(_BYTE *)(a1 + 308) = 0;
return v2 - __readfsqword(0x28u);
}

original_code: void user_unsetawaymsg (struct user *u) { *u->awaymsg = '\0'; }

canonical_original_code: void user_unsetawaymsg(struct user *u) { *u->awaymsg = '\0'; }


decompiled_code:
unsigned __int64 __fastcall user_setaccount(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned __int64 v9; // [rsp+8h] [rbp-30h]

v9 = __readfsqword(0x28u);
strncpyz((char *)a1 + 204, a2, 16LL);
a1[28] = a3;
a1[29] = a4;
a1[30] = a5;
return v9 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func13(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned __int64 v9; // [rsp+8h] [rbp-30h]

v9 = __readfsqword(0x28u);
strncpyz((char *)a1 + 204, a2, 16LL);
a1[28] = a3;
a1[29] = a4;
a1[30] = a5;
return v9 - __readfsqword(0x28u);
}

original_code:
void user_setaccount(struct user *u, char *accname, time_t ts, long id, long flags) {
 strncpyz((u->account), (accname), sizeof(u->account));
 u->acctime = ts;
 u->accid = id;
 u->accflags = flags;
}

canonical_original_code:
void user_setaccount(struct user *u, char *accname, long ts, long id, long flags) {
 strncpyz((u->account), (accname), sizeof(u->account));
 u->acctime = ts;
 u->accid = id;
 u->accflags = flags;
}

variable_types:
accname
char *

variable_types: ts long

variable_types: id long

variable_types: flags long


decompiled_code:
unsigned __int64 __fastcall user_setaccountcolon(_QWORD *a1, __int64 a2)
{
__int64 v2; // r13
__int64 v3; // rbp
__int64 v4; // r12
__int64 v5; // r8
char v7[8]; // [rsp+0h] [rbp-838h] BYREF
__int64 v8; // [rsp+8h] [rbp-830h]
char *nptr; // [rsp+10h] [rbp-828h]
char *v10; // [rsp+18h] [rbp-820h]
char *v11; // [rsp+20h] [rbp-818h]
unsigned __int64 v12; // [rsp+808h] [rbp-30h]

v12 = __readfsqword(0x28u);
split(v7, a2, 58LL);
if ( v7[0] )
{
v2 = v8;
v3 = 0LL;
if ( v7[0] > 1u )
v3 = strtol(nptr, 0LL, 10);
v4 = 0LL;
if ( v7[0] > 2u )
v4 = strtol(v10, 0LL, 10);
v5 = 0LL;
if ( v7[0] > 3u )
v5 = strtol(v11, 0LL, 10);
user_setaccount(a1, v2, v3, v4, v5);
}
else
{
logtxt(256LL, "Invalid +r parameter\n");
}
return v12 - __readfsqword(0x28u);
}

original_code:
static void user_setaccountcolon(struct user *u, char *param) {
 struct manyargs arg;
 char *accname;
 time_t ts;
 long id, flags;
 split(&arg, param, ':');
 if (arg.c == 0) {
  logtxt(0x0100, "Invalid +r parameter" "\n");
  return;
 }
 accname = arg.v[0];
 ts = arg.c > 1 ? (time_t)strtol(arg.v[1], ((void *)0), 10) : 0;
 id = arg.c > 2 ? strtol(arg.v[2], ((void *)0), 10) : 0;
 flags = arg.c > 3 ? strtol(arg.v[3], ((void *)0), 10) : 0;
 user_setaccount(u, accname, ts, id, flags);
}

canonical_original_code:
static void user_setaccountcolon(struct user *u, char *param) {
 struct manyargs arg;
 char *accname;
 long ts;
 long id; long flags;
 split(&arg, param, ':');
 if (arg.c == 0) {
  logtxt(0x0100, "Invalid +r parameter" "\n");
  return;
 }
 accname = arg.v[0];
 ts = arg.c > 1 ? (long)strtol(arg.v[1], ((void *)0), 10) : 0;
 id = arg.c > 2 ? strtol(arg.v[2], ((void *)0), 10) : 0;
 flags = arg.c > 3 ? strtol(arg.v[3], ((void *)0), 10) : 0;
 user_setaccount(u, accname, ts, id, flags);
}

variable_types:
param
char *

variable_types: struct manyargs { unsigned char c; char *v[256]; }


original_code:
void user_unsetaccount(struct user *u) {
 u->account[0] = '0';
 u->account[1] = '\0';
 u->acctime = 0;
 u->accflags = 0;
 u->accid = 0;
}


decompiled_code:
__int64 __fastcall user_modehook(__int64 a1, _QWORD *a2, unsigned int a3, char a4, __int64 a5)
{
__int64 result; // rax

if ( *(_DWORD *)a2 != 18929 )
{
logtxt(16LL, "Mode change for not-a-user!\n");
return 4294967293LL;
}
if ( a4 == 111 )
{
if ( a3 && a5 )
{
user_setopername((__int64)a2, a5);
LABEL_18:
jtableP_set(&opers, a2);
return 0LL;
}
LABEL_15:
if ( !a3 )
{
jtableP_unset(&opers, a2);
return 0LL;
}
goto LABEL_18;
}
if ( a4 <= 111 )
{
if ( a4 != 79 )
{
if ( a4 != 104 )
return 0LL;
if ( a3 )
{
user_setfakehost((__int64)a2, a5);
result = 0LL;
}
else
{
user_unsetfakehost((__int64)a2);
result = a3;
}
return result;
}
goto LABEL_15;
}
result = 0LL;
if ( a4 == 114 )
{
if ( a3 )
{
user_setaccountcolon(a2, a5);
result = 0LL;
}
else
{
user_unsetaccount((__int64)a2);
result = a3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, _QWORD *a2, unsigned int a3, char a4, __int64 a5)
{
__int64 result; // rax

if ( *(_DWORD *)a2 != 18929 )
{
logtxt(16LL, "Mode change for not-a-user!\n");
return 4294967293LL;
}
if ( a4 == 111 )
{
if ( a3 && a5 )
{
func7((__int64)a2, a5);
LABEL_18:
jtableP_set(&opers, a2);
return 0LL;
}
LABEL_15:
if ( !a3 )
{
jtableP_unset(&opers, a2);
return 0LL;
}
goto LABEL_18;
}
if ( a4 <= 111 )
{
if ( a4 != 79 )
{
if ( a4 != 104 )
return 0LL;
if ( a3 )
{
func9((__int64)a2, a5);
result = 0LL;
}
else
{
func10((__int64)a2);
result = a3;
}
return result;
}
goto LABEL_15;
}
result = 0LL;
if ( a4 == 114 )
{
if ( a3 )
{
func14(a2, a5);
result = 0LL;
}
else
{
func15((__int64)a2);
result = a3;
}
}
return result;
}

original_code:
int user_modehook(struct entity *from, struct entity *target, int pls, char modechange, char *param) {
 struct user *u;
 u = (struct user *)target;
 if (!(((struct entity *)(u))->magic == 0x49F1)) {
  logtxt(0x0010, "Mode change for not-a-user!" "\n");
  return -3;
 }
 switch (modechange) {
 case 'o':
  if (pls && param)
   user_setopername(u, param);
 case 'O':
  pls ? jtableP_set(&opers, u) : jtableP_unset(&opers, u);
  break;
 case 'h':
  pls ? user_setfakehost(u, param) : user_unsetfakehost(u);
  break;
 case 'r':
  pls ? user_setaccountcolon(u, param) : user_unsetaccount(u);
  break;
 }
 return 0;
}

variable_types:
from
struct entity { unsigned int magic; } *

variable_types:
target
struct entity *

variable_types: pls int

variable_types: modechange char


decompiled_code:
unsigned __int64 __fastcall user_apply_mode(__int64 a1, _DWORD *a2, __int64 a3, __int64 a4, unsigned int a5)
{
unsigned __int64 v6; // [rsp+8h] [rbp-10h]

v6 = __readfsqword(0x28u);
if ( *a2 == 18929 )
mode_apply(a1, a2, a2 + 118, a3, a4, a5, user_modehook);
else
logtxt(256LL, "Usermode change on non-user\n");
return v6 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func17(__int64 a1, _DWORD *a2, __int64 a3, __int64 a4, unsigned int a5)
{
unsigned __int64 v6; // [rsp+8h] [rbp-10h]

v6 = __readfsqword(0x28u);
if ( *a2 == 18929 )
mode_apply(a1, a2, a2 + 118, a3, a4, a5, user_modehook);
else
logtxt(256LL, "Usermode change on non-user\n");
return v6 - __readfsqword(0x28u);
}

original_code:
void user_apply_mode(struct entity *from, struct user *target, char *modechanges, struct manyargs *arg, int skip) {
 if (!(((struct entity *)(target))->magic == 0x49F1)) {
  logtxt(0x0100, "Usermode change on non-user" "\n");
  return;
 }
 mode_apply(from, (struct entity *)target, &target->mode, modechanges, arg, skip, user_modehook);
}

variable_types:
modechanges
char *

variable_types: struct manyargs { unsigned char c; char *v[256]; } *

variable_types: skip int


decompiled_code:
__int64 __fastcall user_isoper(__int64 a1)
{
return jtableP_check(&opers, a1);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return jtableP_check(&opers, a1);
}

original_code:
int user_isoper(struct user *u) {
 return jtableP_check(&opers, u);
}

variable_types: struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP { void *t; } channels; struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP users; unsigned long mode; } *server; } *


decompiled_code:
unsigned __int64 init_base64()
{
int i; // eax
int v1; // edx
unsigned __int8 v2; // al
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
for ( i = 0; i != 256; ++i )
base64table[(unsigned __int8)i] = -1;
v1 = 0;
v2 = 65;
do
{
base64table[v2] = v1++;
v2 = base64chars[(unsigned __int8)v1];
}
while ( v2 );
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func0()
{
int i; // eax
int v1; // edx
unsigned __int8 v2; // al
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
for ( i = 0; i != 256; ++i )
base64table[(unsigned __int8)i] = -1;
v1 = 0;
v2 = 65;
do
{
base64table[v2] = v1++;
v2 = base64chars[(unsigned __int8)v1];
}
while ( v2 );
return v4 - __readfsqword(0x28u);
}

original_code:
void init_base64(void) {
 int i;
 for (i = 0; i < sizeof(base64table); i++)
  base64table[(unsigned char)(i)] = -1;
 for (i = 0; base64chars[(unsigned char)(i)]; i++)
  base64table[(unsigned char)(base64chars[(unsigned char)(i)])] = i;
}

canonical_original_code:
void init_base64() {
 int i;
 for (i = 0; i < sizeof(base64table); i++)
  base64table[(unsigned char)(i)] = -1;
 for (i = 0; base64chars[(unsigned char)(i)]; i++)
  base64table[(unsigned char)(base64chars[(unsigned char)(i)])] = i;
}

variable_types: i int


decompiled_code:
__int64 __fastcall base64_decode_long(__int64 a1, unsigned __int64 a2)
{
__int64 result; // rax
unsigned __int64 v3; // rdx

result = 0LL;
v3 = 0LL;
while ( !a2 )
{
if ( !*(_BYTE *)(a1 + v3) )
return result;
LABEL_3:
result = (char)base64table[*(unsigned __int8 *)(a1 + v3++)] + (result << 6);
}
if ( a2 > v3 )
goto LABEL_3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int64 a2)
{
__int64 result; // rax
unsigned __int64 v3; // rdx

result = 0LL;
v3 = 0LL;
while ( !a2 )
{
if ( !*(_BYTE *)(a1 + v3) )
return result;
LABEL_3:
result = (char)base64table[*(unsigned __int8 *)(a1 + v3++)] + (result << 6);
}
if ( a2 > v3 )
goto LABEL_3;
return result;
}

original_code:
long base64_decode_long(const char *str, size_t len) {
 int i = 0;
 long result = 0;
 for (i = 0; len ? i < len : str[i]; i++) {
  result *= 64;
  result += base64table[(unsigned char)(str[i])];
 }
 return result;
}

canonical_original_code:
long base64_decode_long(char *str, unsigned long len) {
 int i = 0;
 long result = 0;
 for (i = 0; len ? i < len : str[i]; i++) {
  result *= 64;
  result += base64table[(unsigned char)(str[i])];
 }
 return result;
}

variable_types:
len
unsigned long

variable_types: result long


decompiled_code:
unsigned __int64 __fastcall base64_encode_padded(unsigned __int64 a1, unsigned __int64 a2, unsigned __int64 a3)
{
_BYTE *v3; // rax

if ( a2 <= 1 )
{
logtxt(16LL, "Base64 encode with too small bufsize\n");
a1 = 0LL;
}
else
{
v3 = (_BYTE *)(a1 + a2 - 1);
*v3 = 0;
do
{
*--v3 = base64chars[a3 & 0x3F];
a3 >>= 6;
}
while ( a1 < (unsigned __int64)v3 );
}
return a1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 a1, unsigned __int64 a2, unsigned __int64 a3)
{
_BYTE *v3; // rax

if ( a2 <= 1 )
{
logtxt(16LL, "Base64 encode with too small bufsize\n");
a1 = 0LL;
}
else
{
v3 = (_BYTE *)(a1 + a2 - 1);
*v3 = 0;
do
{
*--v3 = base64chars[a3 & 0x3F];
a3 >>= 6;
}
while ( a1 < (unsigned __int64)v3 );
}
return a1;
}

original_code:
char *base64_encode_padded(char *buf, size_t bufsize, unsigned long num) {
 char *e;
 if (bufsize < 2) {
  logtxt(0x0010, "Base64 encode with too small bufsize" "\n");
  return ((void *)0);
 }
 e = buf + bufsize - 1;
 *e = '\0';
 do {
  *(--e) = base64chars[(unsigned char)(num % 64)];
  num /= 64;
 } while (e > buf);
 return buf;
}

canonical_original_code:
char *base64_encode_padded(char *buf, unsigned long bufsize, unsigned long num) {
 char *e;
 if (bufsize < 2) {
  logtxt(0x0010, "Base64 encode with too small bufsize" "\n");
  return ((void *)0);
 }
 e = buf + bufsize - 1;
 *e = '\0';
 do {
  *(--e) = base64chars[(unsigned char)(num % 64)];
  num /= 64;
 } while (e > buf);
 return buf;
}

variable_types:
buf
char *

variable_types:
bufsize
unsigned long

variable_types:
num
unsigned long

variable_types:
e
char *


decompiled_code:
__int64 __fastcall base64_incr(unsigned __int64 a1, unsigned __int64 a2)
{
_BYTE *v2; // rax
char v3; // dl
__int64 result; // rax

if ( a2 <= 1 )
{
logtxt(16LL, "Base64 incr with too small bufsize\n");
result = 1LL;
}
else
{
v2 = (_BYTE *)(a1 + a2 - 2);
if ( a1 > (unsigned __int64)v2 )
{
result = 1LL;
}
else
{
while ( 1 )
{
v3 = base64table[(unsigned __int8)*v2];
if ( v3 != 63 )
break;
*v2-- = 65;
if ( a1 > (unsigned __int64)v2 )
return 1LL;
}
*v2 = base64chars[(unsigned __int8)(v3 + 1)];
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 a1, unsigned __int64 a2)
{
_BYTE *v2; // rax
char v3; // dl
__int64 result; // rax

if ( a2 <= 1 )
{
logtxt(16LL, "Base64 incr with too small bufsize\n");
result = 1LL;
}
else
{
v2 = (_BYTE *)(a1 + a2 - 2);
if ( a1 > (unsigned __int64)v2 )
{
result = 1LL;
}
else
{
while ( 1 )
{
v3 = base64table[(unsigned __int8)*v2];
if ( v3 != 63 )
break;
*v2-- = 65;
if ( a1 > (unsigned __int64)v2 )
return 1LL;
}
*v2 = base64chars[(unsigned __int8)(v3 + 1)];
result = 0LL;
}
}
return result;
}

original_code:
int base64_incr(char *buf, size_t bufsize) {
 char *e, t;
 if (bufsize < 2) {
  logtxt(0x0010, "Base64 incr with too small bufsize" "\n");
  return 1;
 }
 e = buf + bufsize - 1;
 while (--e >= buf) {
  t = base64table[(unsigned char)(*e)];
  if (t == 63)
   *e = base64chars[0];
  else {
   *e = base64chars[(unsigned char)(t + 1)];
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
int base64_incr(char *buf, unsigned long bufsize) {
 char *e; char t;
 if (bufsize < 2) {
  logtxt(0x0010, "Base64 incr with too small bufsize" "\n");
  return 1;
 }
 e = buf + bufsize - 1;
 while (--e >= buf) {
  t = base64table[(unsigned char)(*e)];
  if (t == 63)
   *e = base64chars[0];
  else {
   *e = base64chars[(unsigned char)(t + 1)];
   return 0;
  }
 }
 return 1;
}

variable_types: t char


decompiled_code:
__int64 __fastcall str2unum(__int64 a1)
{
return base64_decode_long(a1, 5uLL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return func1(a1, 5uLL);
}

original_code:
unsigned long str2unum(const char *str) {
 return base64_decode_long(str, 5);
}

canonical_original_code:
unsigned long str2unum(char *str) {
 return base64_decode_long(str, 5);
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall str2snum(__int64 a1)
{
return base64_decode_long(a1, 2uLL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return func1(a1, 2uLL);
}

original_code:
unsigned long str2snum(const char *str) {
 return base64_decode_long(str, 2);
}

canonical_original_code:
unsigned long str2snum(char *str) {
 return base64_decode_long(str, 2);
}


decompiled_code:
void *__fastcall unum2str(unsigned __int64 a1)
{
base64_encode_padded((unsigned __int64)&buf_2, 6uLL, a1);
return &buf_2;
}

canonical_decompiled_code:
void *__fastcall func6(unsigned __int64 a1)
{
func2((unsigned __int64)&buf_2, 6uLL, a1);
return &buf_2;
}

original_code:
const char *unum2str(unsigned long unum) {
 static char buf[5 +1];
 base64_encode_padded(buf, sizeof(buf), unum);
 return buf;
}

canonical_original_code:
char *unum2str(unsigned long unum) {
 static char buf[-1];
 base64_encode_padded(buf, sizeof(buf), unum);
 return buf;
}

variable_types:
unum
unsigned long

variable_types:
buf
char [-1]


decompiled_code:
void *__fastcall snum2str(unsigned __int64 a1)
{
base64_encode_padded((unsigned __int64)&buf_1, 3uLL, a1);
return &buf_1;
}

canonical_decompiled_code:
void *__fastcall func7(unsigned __int64 a1)
{
func2((unsigned __int64)&buf_1, 3uLL, a1);
return &buf_1;
}

original_code:
const char *snum2str(unsigned long snum) {
 static char buf[2 +1];
 base64_encode_padded(buf, sizeof(buf), snum);
 return buf;
}

canonical_original_code:
char *snum2str(unsigned long snum) {
 static char buf[-1];
 base64_encode_padded(buf, sizeof(buf), snum);
 return buf;
}

variable_types:
snum
unsigned long


decompiled_code:
void *__fastcall cnum2str(__int64 a1, __int64 a2)
{
base64_encode_padded((unsigned __int64)&buf_0, 6uLL, (a1 << 18) + a2);
return &buf_0;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1, __int64 a2)
{
func2((unsigned __int64)&buf_0, 6uLL, (a1 << 18) + a2);
return &buf_0;
}

original_code:
const char *cnum2str(unsigned long snum, unsigned long cnum) {
 static char buf[5 +1];
 base64_encode_padded(buf, sizeof(buf), snum*64*64*64+cnum);
 return buf;
}

canonical_original_code:
char *cnum2str(unsigned long snum, unsigned long cnum) {
 static char buf[-1];
 base64_encode_padded(buf, sizeof(buf), snum*64*64*64+cnum);
 return buf;
}

variable_types:
cnum
unsigned long


decompiled_code:
__int64 __fastcall module_register(__int64 a1, const char *a2, const char *a3)
{
char *v4; // rax
__int64 v5; // rdx
__int64 v6; // r10

if ( !modules[0] )
{
v5 = 0LL;
LABEL_5:
v6 = 3LL * (int)v5;
modules[v6] = a1;
modules[v6 + 1] = a2;
modules[v6 + 2] = a3;
logfmt(0x4000LL, "Module added - index: %d - name: %s - description: %s\n", v5, a2, a3);
return 0LL;
}
v4 = (char *)&modules[3];
LODWORD(v5) = 0;
do
{
v5 = (unsigned int)(v5 + 1);
v4 += 24;
}
while ( *((_QWORD *)v4 - 3) );
if ( (int)v5 <= 100 )
goto LABEL_5;
logfmt(256LL, "Cannot load module '%s' - max modules limit exceeded.\n", a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, const char *a3)
{
char *v4; // rax
__int64 v5; // rdx
__int64 v6; // r10

if ( !modules[0] )
{
v5 = 0LL;
LABEL_5:
v6 = 3LL * (int)v5;
modules[v6] = a1;
modules[v6 + 1] = a2;
modules[v6 + 2] = a3;
logfmt(0x4000LL, "Module added - index: %d - name: %s - description: %s\n", v5, a2, a3);
return 0LL;
}
v4 = (char *)&modules[3];
LODWORD(v5) = 0;
do
{
v5 = (unsigned int)(v5 + 1);
v4 += 24;
}
while ( *((_QWORD *)v4 - 3) );
if ( (int)v5 <= 100 )
goto LABEL_5;
logfmt(256LL, "Cannot load module '%s' - max modules limit exceeded.\n", a2);
return 1LL;
}

original_code:
int module_register(void *module, const char *name, const char *description) {
 int index = 0;
 for (; modules[index].module != ((void *)0); index++);
 if (index > 100) {
  logfmt(0x0100, "Cannot load module '%s' - max modules limit exceeded." "\n", name);
  return 1;
 }
 modules[index].module = module;
 modules[index].name = name;
 modules[index].description = description;
 logfmt(0x4000, "Module added - index: %d - name: %s - description: %s" "\n", index, name, description);
 return 0;
}

canonical_original_code:
int module_register(void *module, char *name, char *description) {
 int index = 0;
 for (; modules[index].module != ((void *)0); index++);
 if (index > 100) {
  logfmt(0x0100, "Cannot load module '%s' - max modules limit exceeded." "\n", name);
  return 1;
 }
 modules[index].module = module;
 modules[index].name = name;
 modules[index].description = description;
 logfmt(0x4000, "Module added - index: %d - name: %s - description: %s" "\n", index, name, description);
 return 0;
}

variable_types:
module
void *

variable_types:
name
char *

variable_types:
description
char *

variable_types: index int


original_code:
int module_unregister(void *module) {
 int position = -1;
 for (int x = 0; x < 100; x++) {
  if (modules[x].module == module) {
   position = x;
   break;
  }
 }
 for (int c = position; c < 100 - 1 ; c++) modules[c] = modules[c+1];
 return 1;
}

variable_types: position int

variable_types: x int

variable_types: c int


decompiled_code:
__int64 __fastcall module_load(char *file, const char *a2, const char *a3)
{
void *v4; // rax
__int64 v5; // rbx
int (*v6)(void); // r14
__int64 result; // rax
char *v8; // rax
char *v9; // rax

logfmt(0x4000LL, "(%s): Loading...\n", a2);
v4 = dlopen(file, 266);
if ( v4 )
{
v5 = (__int64)v4;
v6 = (int (*)(void))dlsym(v4, "load");
if ( dlerror() )
{
v9 = dlerror();
logfmt(16LL, "Cannot call 'load' for %s - error: %s\n", file, v9);
result = 1LL;
}
else if ( v6() > 0 )
{
logfmt(16LL, "(%s): load() was called, and exited with error.\n", a2);
result = 1LL;
}
else
{
module_register(v5, a2, a3);
result = 0LL;
}
}
else
{
v8 = dlerror();
logfmt(16LL, "Cannot load %s - error: %s\n", a2, v8);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *file, const char *a2, const char *a3)
{
void *v4; // rax
__int64 v5; // rbx
int (*v6)(void); // r14
__int64 result; // rax
char *v8; // rax
char *v9; // rax

logfmt(0x4000LL, "(%s): Loading...\n", a2);
v4 = dlopen(file, 266);
if ( v4 )
{
v5 = (__int64)v4;
v6 = (int (*)(void))dlsym(v4, "load");
if ( dlerror() )
{
v9 = dlerror();
logfmt(16LL, "Cannot call 'load' for %s - error: %s\n", file, v9);
result = 1LL;
}
else if ( v6() > 0 )
{
logfmt(16LL, "(%s): load() was called, and exited with error.\n", a2);
result = 1LL;
}
else
{
func0(v5, a2, a3);
result = 0LL;
}
}
else
{
v8 = dlerror();
logfmt(16LL, "Cannot load %s - error: %s\n", a2, v8);
result = 1LL;
}
return result;
}

original_code:
int module_load(const char *path, const char *name, const char *description) {
 logfmt(0x4000, "(%s): Loading..." "\n", name);
 void *module;
 module = dlopen(path, 0x00002 | 0x00100 | 0x00008);
 if (!module) {
  logfmt(0x0010, "Cannot load %s - error: %s" "\n", name, dlerror());
  return 1;
 }
 module_func init;
 init = dlsym(module, "load");
 if (dlerror()) {
  logfmt(0x0010, "Cannot call 'load' for %s - error: %s" "\n", path, dlerror());
  return 1;
 }
 int res = init();
 if (res > 0) {
  logfmt(0x0010, "(%s): load() was called, and exited with error." "\n", name);
  return 1;
 }
 module_register(module, name, description);
 return 0;
}

canonical_original_code:
int module_load(char *path, char *name, char *description) {
 logfmt(0x4000, "(%s): Loading..." "\n", name);
 void *module;
 module = dlopen(path, 0x00002 | 0x00100 | 0x00008);
 if (!module) {
  logfmt(0x0010, "Cannot load %s - error: %s" "\n", name, dlerror());
  return 1;
 }
 int (*init)();
 init = dlsym(module, "load");
 if (dlerror()) {
  logfmt(0x0010, "Cannot call 'load' for %s - error: %s" "\n", path, dlerror());
  return 1;
 }
 int res = init();
 if (res > 0) {
  logfmt(0x0010, "(%s): load() was called, and exited with error." "\n", name);
  return 1;
 }
 module_register(module, name, description);
 return 0;
}

variable_types:
path
char *

variable_types:
init
int (*)()

variable_types: res int


decompiled_code:
__int64 __fastcall module_find_by_name(char *s2)
{
size_t v1; // r13
const char **v2; // rbp
int v3; // ebx

v1 = strlen(s2);
v2 = (const char **)&modules[1];
v3 = 0;
while ( strncmp(*v2, s2, v1) )
{
++v3;
v2 += 3;
if ( v3 == 100 )
return 0LL;
}
return modules[3 * v3];
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2)
{
size_t v1; // r13
const char **v2; // rbp
int v3; // ebx

v1 = strlen(s2);
v2 = (const char **)&modules[1];
v3 = 0;
while ( strncmp(*v2, s2, v1) )
{
++v3;
v2 += 3;
if ( v3 == 100 )
return 0LL;
}
return modules[3 * v3];
}

original_code:
void * module_find_by_name(const char *name) {
 for (int x = 0; x < 100; x++) {
  if (!strncmp(modules[x].name, name, strlen(name))) {
   return modules[x].module;
  }
 }
 return ((void *)0);
}

canonical_original_code:
void *module_find_by_name(char *name) {
 for (int x = 0; x < 100; x++) {
  if (!strncmp(modules[x].name, name, strlen(name))) {
   return modules[x].module;
  }
 }
 return ((void *)0);
}


decompiled_code:
__int64 __fastcall module_unload(char *a1)
{
void *v1; // rbx
__int64 result; // rax
__int64 (*v3)(void); // r12
char *v4; // rax

v1 = (void *)module_find_by_name(a1);
result = 1LL;
if ( v1 )
{
v3 = (__int64 (*)(void))dlsym(v1, "unload");
if ( dlerror() )
{
v4 = dlerror();
logfmt(16LL, "Cannot call 'unload' for %s - error: %s\n", a1, v4);
result = 1LL;
}
else
{
module_unregister((__int64)v1);
result = v3();
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
void *v1; // rbx
__int64 result; // rax
__int64 (*v3)(void); // r12
char *v4; // rax

v1 = (void *)func3(a1);
result = 1LL;
if ( v1 )
{
v3 = (__int64 (*)(void))dlsym(v1, "unload");
if ( dlerror() )
{
v4 = dlerror();
logfmt(16LL, "Cannot call 'unload' for %s - error: %s\n", a1, v4);
result = 1LL;
}
else
{
func1((__int64)v1);
result = v3();
}
}
return result;
}

original_code:
int module_unload(const char *name) {
 void *mod = module_find_by_name(name);
 if (mod == ((void *)0)) return 1;
 module_func unload;
 unload = dlsym(mod, "unload");
 if (dlerror()) {
  logfmt(0x0010, "Cannot call 'unload' for %s - error: %s" "\n", name, dlerror());
  return 1;
 }
 module_unregister(mod);
 int result = unload();
 return result;
}

canonical_original_code:
int module_unload(char *name) {
 void *mod = module_find_by_name(name);
 if (mod == ((void *)0)) return 1;
 int (*unload)();
 unload = dlsym(mod, "unload");
 if (dlerror()) {
  logfmt(0x0010, "Cannot call 'unload' for %s - error: %s" "\n", name, dlerror());
  return 1;
 }
 module_unregister(mod);
 int result = unload();
 return result;
}

variable_types:
mod
void *

variable_types:
unload
int (*)()

variable_types: result int


decompiled_code:
__int64 __fastcall module_get_description(char *s2)
{
size_t v1; // r13
const char **v2; // rbp
int v3; // ebx

v1 = strlen(s2);
v2 = (const char **)&modules[1];
v3 = 0;
while ( strncmp(*v2, s2, v1) )
{
++v3;
v2 += 3;
if ( v3 == 100 )
return 0LL;
}
return modules[3 * v3 + 2];
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2)
{
size_t v1; // r13
const char **v2; // rbp
int v3; // ebx

v1 = strlen(s2);
v2 = (const char **)&modules[1];
v3 = 0;
while ( strncmp(*v2, s2, v1) )
{
++v3;
v2 += 3;
if ( v3 == 100 )
return 0LL;
}
return modules[3 * v3 + 2];
}

original_code:
const char *module_get_description(const char *name) {
 for (int x = 0; x < 100; x++) {
  if (!strncmp(modules[x].name, name, strlen(name))) {
   return modules[x].description;
  }
 }
 return ((void *)0);
}

canonical_original_code:
char *module_get_description(char *name) {
 for (int x = 0; x < 100; x++) {
  if (!strncmp(modules[x].name, name, strlen(name))) {
   return modules[x].description;
  }
 }
 return ((void *)0);
}


decompiled_code:
unsigned __int64 module_loadAll()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
module_load("modules/lua.so", "lua", "PLServices Lua Module.");
module_load("modules/tcl.so", "tcl", "PLServices TCL Module.");
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func6()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
func2("modules/lua.so", "lua", "PLServices Lua Module.");
func2("modules/tcl.so", "tcl", "PLServices TCL Module.");
return v1 - __readfsqword(0x28u);
}

original_code:
void module_loadAll() {
 module_load("modules/lua.so", "lua", "PLServices Lua Module.");
 module_load("modules/tcl.so", "tcl", "PLServices TCL Module.");
}


decompiled_code:
unsigned __int64 __fastcall module_join_channel(__int64 a1, const char *a2, int a3)
{
__int64 v4; // rax
const char *v5; // rbp
unsigned __int64 v7; // [rsp+8h] [rbp-20h]

v7 = __readfsqword(0x28u);
v4 = get_channel_by_name(a2);
if ( v4 )
{
v5 = (const char *)(v4 + 4);
send_format("%s J %s %ld\r\n", (const char *)(a1 + 16), (const char *)(v4 + 4), *(_QWORD *)(v4 + 488));
if ( a3 )
send_format("%s M %s +o %s\r\n", (const char *)(me + 24LL), v5, (const char *)(a1 + 16));
}
else
{
send_format("%s C %s %ld\r\n", (const char *)(a1 + 16), a2, now);
}
return v7 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(__int64 a1, const char *a2, int a3)
{
__int64 v4; // rax
const char *v5; // rbp
unsigned __int64 v7; // [rsp+8h] [rbp-20h]

v7 = __readfsqword(0x28u);
v4 = get_channel_by_name(a2);
if ( v4 )
{
v5 = (const char *)(v4 + 4);
send_format("%s J %s %ld\r\n", (const char *)(a1 + 16), (const char *)(v4 + 4), *(_QWORD *)(v4 + 488));
if ( a3 )
send_format("%s M %s +o %s\r\n", (const char *)(me + 24LL), v5, (const char *)(a1 + 16));
}
else
{
send_format("%s C %s %ld\r\n", (const char *)(a1 + 16), a2, now);
}
return v7 - __readfsqword(0x28u);
}

original_code:
void module_join_channel(struct user *from, const char *channel, int auto_op) {
 struct channel *chan = get_channel_by_name(channel);
 if (chan == ((void *)0)) {
  send_format("%s C %s %ld" "\r\n", from->numericstr, channel, now);
 } else {
  send_format("%s J %s %ld" "\r\n", from->numericstr, chan->name, chan->ts);
  if (auto_op) {
   send_format("%s M %s +o %s" "\r\n", me->numericstr, chan->name, from->numericstr);
  }
 }
}

canonical_original_code:
void module_join_channel(struct user *from, char *channel, int auto_op) {
 struct channel *chan = get_channel_by_name(channel);
 if (chan == ((void *)0)) {
  send_format("%s C %s %ld" "\r\n", from->numericstr, channel, now);
 } else {
  send_format("%s J %s %ld" "\r\n", from->numericstr, chan->name, chan->ts);
  if (auto_op) {
   send_format("%s M %s +o %s" "\r\n", me->numericstr, chan->name, from->numericstr);
  }
 }
}

variable_types: struct user { unsigned int magic; unsigned long numeric; char numericstr[-1]; char nick[-1]; char user[-1]; char host[-1]; char fakehost[-1]; char opername[-1]; char account[-1]; long acctime; long accid; char realname[-1]; int hops; unsigned int accountid; char awaymsg[-1]; unsigned long mode; int channelcount; struct jtableP { void *t; } channels; struct server { unsigned int magic; unsigned long numeric; unsigned long lastnumeric; char numericstr[-1]; char name[-1]; unsigned long maxusers; int hops; long boot; long link; char protocol[4]; char description[-1]; struct jtableP users; unsigned long mode; } *server; } *

variable_types:
channel
char *

variable_types: struct channel { unsigned int magic; char name[-1]; char key[-1]; char topic[-1]; long limit; long ts; int usercount; unsigned long mode; struct jtableP { void *t; } ops; struct jtableS { void *t; } bans; } *


decompiled_code:
unsigned __int64 __fastcall module_part_channel(__int64 a1, const char *a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
if ( get_channel_by_name(a2) )
send_format("%s L %s\r\n", (const char *)(a1 + 16), a2);
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 a1, const char *a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
if ( get_channel_by_name(a2) )
send_format("%s L %s\r\n", (const char *)(a1 + 16), a2);
return v3 - __readfsqword(0x28u);
}

original_code:
void module_part_channel(struct user *from, const char *channel) {
 if (get_channel_by_name(channel) == ((void *)0)) return;
 send_format("%s L %s" "\r\n", from->numericstr, channel);
}

canonical_original_code:
void module_part_channel(struct user *from, char *channel) {
 if (get_channel_by_name(channel) == ((void *)0)) return;
 send_format("%s L %s" "\r\n", from->numericstr, channel);
}


decompiled_code:
unsigned __int64 module_describe(__int64 a1, __int64 a2, const char *a3, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
unsigned __int64 v5; // [rsp+18h] [rbp-D0h]

va_start(va, a3);
v5 = __readfsqword(0x28u);
vsprintf(buf_2, a3, va);
if ( get_channel_by_name(a2) || get_user_by_numericstr(a2) )
send_format(LC19, a1 + 16, a2, buf_2);
return v5 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func9(__int64 a1, __int64 a2, const char *a3, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
unsigned __int64 v5; // [rsp+18h] [rbp-D0h]

va_start(va, a3);
v5 = __readfsqword(0x28u);
vsprintf(buf_2, a3, va);
if ( get_channel_by_name(a2) || get_user_by_numericstr(a2) )
send_format(LC19, a1 + 16, a2, buf_2);
return v5 - __readfsqword(0x28u);
}

original_code:
void module_describe(struct user *from, const char *target, const char *message, ...) {
 static char buf[512];
 va_list ap;
 __builtin_va_start(ap,message);
 vsprintf(buf, message, ap);
 __builtin_va_end(ap);
 if (get_channel_by_name(target) == ((void *)0) && get_user_by_numericstr(target) == ((void *)0)) return;
 send_format("%s P %s :\001ACTION %s\001" "\r\n", from->numericstr, target, buf);
}

canonical_original_code:
void module_describe(struct user *from, char *target, char *message, ...) {
 static char buf[512];
 __builtin_va_list ap;
 __builtin_va_start(ap,message);
 vsprintf(buf, message, ap);
 __builtin_va_end(ap);
 if (get_channel_by_name(target) == ((void *)0) && get_user_by_numericstr(target) == ((void *)0)) return;
 send_format("%s P %s :\001ACTION %s\001" "\r\n", from->numericstr, target, buf);
}

variable_types:
target
char *

variable_types:
message
char *

variable_types:
buf
char [512]


decompiled_code:
unsigned __int64 module_privmsg(__int64 a1, const char *a2, const char *a3, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
unsigned __int64 v5; // [rsp+18h] [rbp-D0h]

va_start(va, a3);
v5 = __readfsqword(0x28u);
vsprintf(buf_1, a3, va);
if ( get_channel_by_name(a2) || get_user_by_numericstr(a2) )
send_format("%s P %s :%s\r\n", (const char *)(a1 + 16), a2, buf_1);
return v5 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func10(__int64 a1, const char *a2, const char *a3, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
unsigned __int64 v5; // [rsp+18h] [rbp-D0h]

va_start(va, a3);
v5 = __readfsqword(0x28u);
vsprintf(buf_1, a3, va);
if ( get_channel_by_name(a2) || get_user_by_numericstr(a2) )
send_format("%s P %s :%s\r\n", (const char *)(a1 + 16), a2, buf_1);
return v5 - __readfsqword(0x28u);
}

original_code:
void module_privmsg(struct user *from, const char *target, const char *message, ...) {
 static char buf[512];
 va_list ap;
 __builtin_va_start(ap,message);
 vsprintf(buf, message, ap);
 __builtin_va_end(ap);
 if (get_channel_by_name(target) == ((void *)0) && get_user_by_numericstr(target) == ((void *)0)) return;
 send_format("%s P %s :%s" "\r\n", from->numericstr, target, buf);
}

canonical_original_code:
void module_privmsg(struct user *from, char *target, char *message, ...) {
 static char buf[512];
 __builtin_va_list ap;
 __builtin_va_start(ap,message);
 vsprintf(buf, message, ap);
 __builtin_va_end(ap);
 if (get_channel_by_name(target) == ((void *)0) && get_user_by_numericstr(target) == ((void *)0)) return;
 send_format("%s P %s :%s" "\r\n", from->numericstr, target, buf);
}


decompiled_code:
unsigned __int64 module_notice(__int64 a1, const char *a2, const char *a3, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
unsigned __int64 v5; // [rsp+18h] [rbp-D0h]

va_start(va, a3);
v5 = __readfsqword(0x28u);
vsprintf(buf_0, a3, va);
if ( get_user_by_numericstr(a2) )
send_format("%s O %s :%s\r\n", (const char *)(a1 + 16), a2, buf_0);
return v5 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func11(__int64 a1, const char *a2, const char *a3, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
unsigned __int64 v5; // [rsp+18h] [rbp-D0h]

va_start(va, a3);
v5 = __readfsqword(0x28u);
vsprintf(buf_0, a3, va);
if ( get_user_by_numericstr(a2) )
send_format("%s O %s :%s\r\n", (const char *)(a1 + 16), a2, buf_0);
return v5 - __readfsqword(0x28u);
}

original_code:
void module_notice(struct user *from, const char *target, const char *message, ...) {
        static char buf[512];
        va_list ap;
        __builtin_va_start(ap,message);
        vsprintf(buf, message, ap);
        __builtin_va_end(ap);
        if (get_user_by_numericstr(target) == ((void *)0)) return;
        send_format("%s O %s :%s" "\r\n", from->numericstr, target, buf);
}

canonical_original_code:
void module_notice(struct user *from, char *target, char *message, ...) {
        static char buf[512];
        __builtin_va_list ap;
        __builtin_va_start(ap,message);
        vsprintf(buf, message, ap);
        __builtin_va_end(ap);
        if (get_user_by_numericstr(target) == ((void *)0)) return;
        send_format("%s O %s :%s" "\r\n", from->numericstr, target, buf);
}