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

while ( !lista_vazia_l((__int64)a1) )
{
v1 = (_QWORD *)a1[13];
free(a1);
a1 = v1;
}
free(a1);
return 0LL;
}

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

while ( !func1((__int64)a1) )
{
v1 = (_QWORD *)a1[13];
free(a1);
a1 = v1;
}
free(a1);
return 0LL;
}

original_code:
Livro destroi_lista_l(Livro lista)
{
    Livro temp_ptr;
    while (lista_vazia_l(lista) == 0)
    {
        temp_ptr = lista;
        lista= lista->prox;
        free (temp_ptr);
    }
    free(lista);
    return ((void *)0);
}

canonical_original_code:
struct no_l *destroi_lista_l(struct no_l *lista)
{
    struct no_l *temp_ptr;
    while (lista_vazia_l(lista) == 0)
    {
        temp_ptr = lista;
        lista= lista->prox;
        free (temp_ptr);
    }
    free(lista);
    return ((void *)0);
}

variable_types:
lista
struct no_l *


repo: AlexPnt/Library-Management-System

decompiled_code:
__int64 lista_cheia_l()
{
return 0LL;
}

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

original_code:
int lista_cheia_l(Livro lista)
{
    return 0;
}

canonical_original_code:
int lista_cheia_l(struct no_l *lista)
{
    return 0;
}

variable_types: struct no_l { struct Livro_str { char nome[100]; int cod_livro; } dados; struct no_l *prox; } *

return_type: int

user_defined_types: struct no_l { struct Livro_str dados; struct no_l *prox; }


decompiled_code:
__int64 __fastcall procura_lista_l(__int64 a1, int a2, _QWORD *a3, _QWORD *a4)
{
__int64 result; // rax

*a3 = a1;
result = *(_QWORD *)(a1 + 104);
*a4 = result;
if ( result )
{
while ( *(_DWORD *)(result + 100) < a2 )
{
*a3 = result;
result = *(_QWORD *)(result + 104);
*a4 = result;
if ( !result )
return result;
}
if ( *(_DWORD *)(result + 100) != a2 )
*a4 = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, _QWORD *a3, _QWORD *a4)
{
__int64 result; // rax

*a3 = a1;
result = *(_QWORD *)(a1 + 104);
*a4 = result;
if ( result )
{
while ( *(_DWORD *)(result + 100) < a2 )
{
*a3 = result;
result = *(_QWORD *)(result + 104);
*a4 = result;
if ( !result )
return result;
}
if ( *(_DWORD *)(result + 100) != a2 )
*a4 = 0LL;
}
return result;
}

original_code:
void procura_lista_l(Livro lista, int chave, Livro *ant, Livro *actual)
{
    *ant = lista; *actual = lista->prox;
    while ((*actual) != ((void *)0) && (*actual)->dados.cod_livro < chave)
    {
        *ant = *actual;
        *actual = (*actual)->prox;
    }
    if ((*actual) != ((void *)0) && (*actual)->dados.cod_livro != chave)
        *actual = ((void *)0);
}

canonical_original_code:
void procura_lista_l(struct no_l *lista, int chave, struct no_l **ant, struct no_l **actual)
{
    *ant = lista; *actual = lista->prox;
    while ((*actual) != ((void *)0) && (*actual)->dados.cod_livro < chave)
    {
        *ant = *actual;
        *actual = (*actual)->prox;
    }
    if ((*actual) != ((void *)0) && (*actual)->dados.cod_livro != chave)
        *actual = ((void *)0);
}

variable_types: chave int

variable_types:
ant
struct no_l **

variable_types:
actual
struct no_l **

return_type: void

user_defined_types: struct Livro_str { char nome[100]; int cod_livro; }


decompiled_code:
__int64 __fastcall pesquisa_lista_l(__int64 a1, int a2)
{
__int64 v3; // [rsp+0h] [rbp-10h] BYREF
__int64 v4; // [rsp+8h] [rbp-8h] BYREF

procura_lista_l(a1, a2, &v3, &v4);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
__int64 v3; // [rsp+0h] [rbp-10h] BYREF
__int64 v4; // [rsp+8h] [rbp-8h] BYREF

func4(a1, a2, &v3, &v4);
return v4;
}

original_code:
Livro pesquisa_lista_l(Livro lista, int chave)
{
    Livro ant;
    Livro actual;
    procura_lista_l(lista,chave, &ant, &actual);
    return (actual);
}

canonical_original_code:
struct no_l *pesquisa_lista_l(struct no_l *lista, int chave)
{
    struct no_l *ant;
    struct no_l *actual;
    procura_lista_l(lista,chave, &ant, &actual);
    return (actual);
}

return_type: struct no_l { struct Livro_str { char nome[100]; int cod_livro; } dados; struct no_l *prox; } *


variable_types: conta int


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

result = malloc(0x30uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
result[5] = 0LL;
}
return result;
}

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

result = malloc(0x30uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
result[5] = 0LL;
}
return result;
}

original_code:
Requisit cria_lista_r(void)
{
    Requisit aux;
    aux = (Requisit) malloc (sizeof (No_requisit));
    if (aux != ((void *)0)) {
        aux->info.cod_livro = 0;
        aux->info.cod_utente = 0;
        aux->info.data_r.dia = 0;
        aux->info.data_r.mes = 0;
        aux->info.data_r.ano = 0;
        aux->prox = ((void *)0);
    }
    return aux;
}

canonical_original_code:
struct no_r *cria_lista_r()
{
    struct no_r *aux;
    aux = (struct no_r *) malloc (sizeof (No_requisit));
    if (aux != ((void *)0)) {
        aux->info.cod_livro = 0;
        aux->info.cod_utente = 0;
        aux->info.data_r.dia = 0;
        aux->info.data_r.mes = 0;
        aux->info.data_r.ano = 0;
        aux->prox = ((void *)0);
    }
    return aux;
}

variable_types: struct no_r { struct Requisit_str { int cod_livro; int cod_utente; struct Data { int dia; int mes; int ano; } data_r; struct Ctrl_fila { struct node_fila { int cod_utente; struct node_fila *prox; } *primeiro; struct node_fila *ultimo; } reserva; } info; struct no_r *prox; } *

user_defined_types: struct no_r { struct Requisit_str info; struct no_r *prox; }

user_defined_types: struct Requisit_str { int cod_livro; int cod_utente; struct Data data_r; struct Ctrl_fila reserva; }

user_defined_types: struct Ctrl_fila { struct node_fila *primeiro; struct node_fila *ultimo; }


decompiled_code:
_BOOL8 __fastcall lista_vazia_r(__int64 a1)
{
return *(_QWORD *)(a1 + 40) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 40) == 0LL;
}

original_code:
int lista_vazia_r(Requisit lista)
{
    return (lista->prox == ((void *)0) ? 1 : 0);
}

canonical_original_code:
int lista_vazia_r(struct no_r *lista)
{
    return (lista->prox == ((void *)0) ? 1 : 0);
}

user_defined_types: struct Data { int dia; int mes; int ano; }

user_defined_types: struct node_fila { int cod_utente; struct node_fila *prox; }


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

while ( !lista_vazia_r((__int64)a1) )
{
v1 = (_QWORD *)a1[5];
free(a1);
a1 = v1;
}
free(a1);
return 0LL;
}

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

while ( !func1((__int64)a1) )
{
v1 = (_QWORD *)a1[5];
free(a1);
a1 = v1;
}
free(a1);
return 0LL;
}

original_code:
Requisit destroi_lista_r(Requisit lista)
{
    Requisit temp_ptr;
    while (lista_vazia_r(lista) == 0)
    {
        temp_ptr = lista;
        lista= lista->prox;
        free (temp_ptr);
    }
    free(lista);
    return ((void *)0);
}

canonical_original_code:
struct no_r *destroi_lista_r(struct no_r *lista)
{
    struct no_r *temp_ptr;
    while (lista_vazia_r(lista) == 0)
    {
        temp_ptr = lista;
        lista= lista->prox;
        free (temp_ptr);
    }
    free(lista);
    return ((void *)0);
}

variable_types:
lista
struct no_r *

return_type: struct no_r { struct Requisit_str { int cod_livro; int cod_utente; struct Data { int dia; int mes; int ano; } data_r; struct Ctrl_fila { struct node_fila { int cod_utente; struct node_fila *prox; } *primeiro; struct node_fila *ultimo; } reserva; } info; struct no_r *prox; } *


decompiled_code:
__int64 lista_cheia_r()
{
return 0LL;
}

original_code:
int lista_cheia_r(Requisit lista)
{
    return 0;
}

canonical_original_code:
int lista_cheia_r(struct no_r *lista)
{
    return 0;
}


decompiled_code:
__int64 __fastcall procura_lista_r(__int64 a1, int a2, _QWORD *a3, _QWORD *a4)
{
__int64 result; // rax

*a3 = a1;
result = *(_QWORD *)(a1 + 40);
*a4 = result;
if ( result )
{
while ( *(_DWORD *)result < a2 )
{
*a3 = result;
result = *(_QWORD *)(result + 40);
*a4 = result;
if ( !result )
return result;
}
if ( *(_DWORD *)result != a2 )
*a4 = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, _QWORD *a3, _QWORD *a4)
{
__int64 result; // rax

*a3 = a1;
result = *(_QWORD *)(a1 + 40);
*a4 = result;
if ( result )
{
while ( *(_DWORD *)result < a2 )
{
*a3 = result;
result = *(_QWORD *)(result + 40);
*a4 = result;
if ( !result )
return result;
}
if ( *(_DWORD *)result != a2 )
*a4 = 0LL;
}
return result;
}

original_code:
void procura_lista_r(Requisit lista, int chave, Requisit *ant, Requisit *actual)
{
    *ant = lista; *actual = lista->prox;
    while ((*actual) != ((void *)0) && (*actual)->info.cod_livro < chave)
    {
        *ant = *actual;
        *actual = (*actual)->prox;
    }
    if ((*actual) != ((void *)0) && (*actual)->info.cod_livro != chave)
        *actual = ((void *)0);
}

canonical_original_code:
void procura_lista_r(struct no_r *lista, int chave, struct no_r **ant, struct no_r **actual)
{
    *ant = lista; *actual = lista->prox;
    while ((*actual) != ((void *)0) && (*actual)->info.cod_livro < chave)
    {
        *ant = *actual;
        *actual = (*actual)->prox;
    }
    if ((*actual) != ((void *)0) && (*actual)->info.cod_livro != chave)
        *actual = ((void *)0);
}

variable_types:
ant
struct no_r **

variable_types:
actual
struct no_r **


decompiled_code:
__int64 __fastcall pesquisa_lista_r(__int64 a1, int a2)
{
__int64 v3; // [rsp+0h] [rbp-10h] BYREF
__int64 v4; // [rsp+8h] [rbp-8h] BYREF

procura_lista_r(a1, a2, &v3, &v4);
return v4;
}

original_code:
Requisit pesquisa_lista_r(Requisit lista, int chave)
{
    Requisit ant;
    Requisit actual;
    procura_lista_r(lista,chave, &ant, &actual);
    return (actual);
}

canonical_original_code:
struct no_r *pesquisa_lista_r(struct no_r *lista, int chave)
{
    struct no_r *ant;
    struct no_r *actual;
    procura_lista_r(lista,chave, &ant, &actual);
    return (actual);
}


decompiled_code:
void __fastcall elimina_lista_r(__int64 a1, int a2)
{
void *v2; // rdi
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
void *ptr; // [rsp+8h] [rbp-10h] BYREF

procura_lista_r(a1, a2, &v3, &ptr);
v2 = ptr;
if ( ptr )
{
*(_QWORD *)(v3 + 40) = *((_QWORD *)ptr + 5);
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2)
{
void *v2; // rdi
__int64 v3; // [rsp+0h] [rbp-18h] BYREF
void *ptr; // [rsp+8h] [rbp-10h] BYREF

func4(a1, a2, &v3, &ptr);
v2 = ptr;
if ( ptr )
{
*(_QWORD *)(v3 + 40) = *((_QWORD *)ptr + 5);
free(v2);
}
}

original_code:
void elimina_lista_r(Requisit lista, int chave)
{
    Requisit ant;
    Requisit actual;
    procura_lista_r(lista,chave,&ant,&actual);
    if (actual != ((void *)0))
    {
        ant->prox = actual->prox;
        free(actual);
    }
}

canonical_original_code:
void elimina_lista_r(struct no_r *lista, int chave)
{
    struct no_r *ant;
    struct no_r *actual;
    procura_lista_r(lista,chave,&ant,&actual);
    if (actual != ((void *)0))
    {
        ant->prox = actual->prox;
        free(actual);
    }
}


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

result = malloc(0x70uLL);
if ( result )
{
result[25] = 0;
*(_WORD *)result = 48;
*((_QWORD *)result + 13) = 0LL;
}
return result;
}

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

result = malloc(0x70uLL);
if ( result )
{
result[25] = 0;
*(_WORD *)result = 48;
*((_QWORD *)result + 13) = 0LL;
}
return result;
}

original_code:
Utente cria_lista_u(void)
{
    Utente aux;
    aux = (Utente) malloc (sizeof (No_utentes));
    if (aux != ((void *)0)) {
        strcpy(aux->registo.nome,"0");
        aux->registo.cod_utente = 0;
        aux->prox = ((void *)0);
    }
    return aux;
}

canonical_original_code:
struct no_u *cria_lista_u()
{
    struct no_u *aux;
    aux = (struct no_u *) malloc (sizeof (No_utentes));
    if (aux != ((void *)0)) {
        strcpy(aux->registo.nome,"0");
        aux->registo.cod_utente = 0;
        aux->prox = ((void *)0);
    }
    return aux;
}

variable_types: struct no_u { struct Utente_str { char nome[100]; int cod_utente; } registo; struct no_u *prox; } *

user_defined_types: struct no_u { struct Utente_str registo; struct no_u *prox; }


decompiled_code:
_BOOL8 __fastcall lista_vazia_u(__int64 a1)
{
return *(_QWORD *)(a1 + 104) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 104) == 0LL;
}

original_code:
int lista_vazia_u(Utente lista)
{
    return (lista->prox == ((void *)0) ? 1 : 0);
}

canonical_original_code:
int lista_vazia_u(struct no_u *lista)
{
    return (lista->prox == ((void *)0) ? 1 : 0);
}

user_defined_types: struct Utente_str { char nome[100]; int cod_utente; }


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

while ( !lista_vazia_u((__int64)a1) )
{
v1 = (_QWORD *)a1[13];
free(a1);
a1 = v1;
}
free(a1);
return 0LL;
}

original_code:
Utente destroi_lista_u(Utente lista)
{
    Utente temp_ptr;
    while (lista_vazia_u(lista) == 0)
    {
        temp_ptr = lista;
        lista= lista->prox;
        free (temp_ptr);
    }
    free(lista);
    return ((void *)0);
}

canonical_original_code:
struct no_u *destroi_lista_u(struct no_u *lista)
{
    struct no_u *temp_ptr;
    while (lista_vazia_u(lista) == 0)
    {
        temp_ptr = lista;
        lista= lista->prox;
        free (temp_ptr);
    }
    free(lista);
    return ((void *)0);
}

variable_types:
lista
struct no_u *

return_type: struct no_u { struct Utente_str { char nome[100]; int cod_utente; } registo; struct no_u *prox; } *


decompiled_code:
__int64 lista_cheia_u()
{
return 0LL;
}

original_code:
int lista_cheia_u(Utente lista)
{
    return 0;
}

canonical_original_code:
int lista_cheia_u(struct no_u *lista)
{
    return 0;
}


decompiled_code:
__int64 __fastcall procura_lista_u(__int64 a1, int a2, _QWORD *a3, _QWORD *a4)
{
__int64 result; // rax

*a3 = a1;
result = *(_QWORD *)(a1 + 104);
*a4 = result;
if ( result )
{
while ( *(_DWORD *)(result + 100) < a2 )
{
*a3 = result;
result = *(_QWORD *)(result + 104);
*a4 = result;
if ( !result )
return result;
}
if ( *(_DWORD *)(result + 100) != a2 )
*a4 = 0LL;
}
return result;
}

original_code:
void procura_lista_u(Utente lista, int chave, Utente *ant, Utente *actual)
{
    *ant = lista; *actual = lista->prox;
    while ((*actual) != ((void *)0) && (*actual)->registo.cod_utente < chave)
    {
        *ant = *actual;
        *actual = (*actual)->prox;
    }
    if ((*actual) != ((void *)0) && (*actual)->registo.cod_utente != chave)
        *actual = ((void *)0);
}

canonical_original_code:
void procura_lista_u(struct no_u *lista, int chave, struct no_u **ant, struct no_u **actual)
{
    *ant = lista; *actual = lista->prox;
    while ((*actual) != ((void *)0) && (*actual)->registo.cod_utente < chave)
    {
        *ant = *actual;
        *actual = (*actual)->prox;
    }
    if ((*actual) != ((void *)0) && (*actual)->registo.cod_utente != chave)
        *actual = ((void *)0);
}

variable_types:
ant
struct no_u **

variable_types:
actual
struct no_u **


decompiled_code:
__int64 __fastcall pesquisa_lista_u(__int64 a1, int a2)
{
__int64 v3; // [rsp+0h] [rbp-10h] BYREF
__int64 v4; // [rsp+8h] [rbp-8h] BYREF

procura_lista_u(a1, a2, &v3, &v4);
return v4;
}

original_code:
Utente pesquisa_lista_u(Utente lista, int chave)
{
    Utente ant;
    Utente actual;
    procura_lista_u(lista,chave, &ant, &actual);
    return (actual);
}

canonical_original_code:
struct no_u *pesquisa_lista_u(struct no_u *lista, int chave)
{
    struct no_u *ant;
    struct no_u *actual;
    procura_lista_u(lista,chave, &ant, &actual);
    return (actual);
}


decompiled_code:
_BOOL8 __fastcall fila_vazia(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
int fila_vazia(Ctrl_fila *fila)
{
 return (fila->primeiro== ((void *)0) ? 1 : 0);
}

canonical_original_code:
int fila_vazia(struct Ctrl_fila *fila)
{
 return (fila->primeiro== ((void *)0) ? 1 : 0);
}

variable_types: struct Ctrl_fila { struct node_fila { int cod_utente; struct node_fila *prox; } *primeiro; struct node_fila *ultimo; } *


decompiled_code:
__int64 fila_cheia()
{
return 0LL;
}

original_code:
int fila_cheia(Ctrl_fila *fila)
{
 return 0;
}

canonical_original_code:
int fila_cheia(struct Ctrl_fila *fila)
{
 return 0;
}


retira

decompiled_code:
__int64 __fastcall retira(unsigned int **a1)
{
unsigned int v2; // er12
void *v3; // r8

if ( fila_vazia(a1) )
return 0LL;
v2 = **a1;
*a1 = (unsigned int *)*((_QWORD *)*a1 + 1);
if ( fila_vazia(a1) )
a1[1] = 0LL;
free(v3);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int **a1)
{
unsigned int v2; // er12
void *v3; // r8

if ( func1(a1) )
return 0LL;
v2 = **a1;
*a1 = (unsigned int *)*((_QWORD *)*a1 + 1);
if ( func1(a1) )
a1[1] = 0LL;
free(v3);
return v2;
}

original_code:
int retira(Ctrl_fila *fila)
{
 f_espera temp;
 int code;
 if (fila_vazia(fila) == 0)
 {
  temp = fila->primeiro;
  code = temp->cod_utente;
  fila->primeiro = fila->primeiro->prox;
  if (fila_vazia(fila) == 1)
   fila->ultimo = ((void *)0);
  free (temp);
  return (code);
 }
 return 0;
}

canonical_original_code:
int retira(struct Ctrl_fila *fila)
{
 struct node_fila *temp;
 int code;
 if (fila_vazia(fila) == 0)
 {
  temp = fila->primeiro;
  code = temp->cod_utente;
  fila->primeiro = fila->primeiro->prox;
  if (fila_vazia(fila) == 1)
   fila->ultimo = ((void *)0);
  free (temp);
  return (code);
 }
 return 0;
}

variable_types: struct node_fila { int cod_utente; struct node_fila *prox; } *

variable_types: code int


getConfStr

repo: AlexanderHaase/mprof

decompiled_code:
char *getConfStr()
{
char *result; // rax

result = (char *)confValue;
if ( !confValue )
{
result = getenv(confKey);
confValue = result;
}
return result;
}

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

result = (char *)confValue;
if ( !confValue )
{
result = getenv(confKey);
confValue = result;
}
return result;
}

original_code:
const char * getConfStr( void ) {
 if( confValue == ((void *)0) ) {
  confValue = getenv( confKey );
 }
 return confValue;
}

canonical_original_code:
char *getConfStr() {
 if( confValue == ((void *)0) ) {
  confValue = getenv( confKey );
 }
 return confValue;
}

return_type: char *


findKey

decompiled_code:
char *__fastcall findKey(char *s1, char *s2)
{
char *v2; // rbx
size_t v3; // rax
size_t v4; // r12

v2 = s1;
v3 = strlen(s2);
if ( !*s1 )
return 0LL;
v4 = v3;
while ( strncmp(v2, s2, v4) )
{
if ( !*++v2 )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(char *s1, char *s2)
{
char *v2; // rbx
size_t v3; // rax
size_t v4; // r12

v2 = s1;
v3 = strlen(s2);
if ( !*s1 )
return 0LL;
v4 = v3;
while ( strncmp(v2, s2, v4) )
{
if ( !*++v2 )
return 0LL;
}
return v2;
}

original_code:
const char * findKey( const char * in_value, const char * in_key ) {
 const size_t keySize = strlen( in_key );
 for( const char * valueItr = in_value; *valueItr != '\0'; valueItr++ ) {
  if( 0 == strncmp( valueItr, in_key, keySize ) ) {
   return valueItr;
  }
 }
 return ((void *)0);
}

canonical_original_code:
char *findKey(char *in_value, char *in_key) {
 unsigned long keySize = strlen( in_key );
 for( char *valueItr = in_value; *valueItr != '\0'; valueItr++ ) {
  if( 0 == strncmp( valueItr, in_key, keySize ) ) {
   return valueItr;
  }
 }
 return ((void *)0);
}

variable_types:
keySize
unsigned long

variable_types:
valueItr
char *


getValue

original_code:
const char * getValue( const char * in_value, size_t * out_size ) {
 if( *in_value != '=' ) {
  return ((void *)0);
 }
 const char delim = *(++in_value);
 const size_t valueSize = strlen( in_value );
 switch( delim ) {
 case '\'':
 case '"':
  ++in_value;
  for( *out_size = 0; *out_size < valueSize - 1; *out_size += 1 ) {
   if( in_value[ *out_size ] == delim ) {
    return in_value;
   }
  }
  return ((void *)0);
 default:
  for( *out_size = 0; *out_size < valueSize; *out_size += 1 ) {
   if( ((*__ctype_b_loc ())[(int) ((in_value[ *out_size ]))] & (unsigned short int) _ISspace) ) {
    break;
   }
  }
  return in_value;
 }
}

canonical_original_code:
char *getValue(char *in_value, unsigned long *out_size) {
 if( *in_value != '=' ) {
  return ((void *)0);
 }
 char delim = *(++in_value);
 unsigned long valueSize = strlen( in_value );
 switch( delim ) {
 case '\'':
 case '"':
  ++in_value;
  for( *out_size = 0; *out_size < valueSize - 1; *out_size += 1 ) {
   if( in_value[ *out_size ] == delim ) {
    return in_value;
   }
  }
  return ((void *)0);
 default:
  for( *out_size = 0; *out_size < valueSize; *out_size += 1 ) {
   if( ((*__ctype_b_loc ())[(int) ((in_value[ *out_size ]))] & (unsigned short) _ISspace) ) {
    break;
   }
  }
  return in_value;
 }
}

variable_types: delim char

variable_types:
valueSize
unsigned long


findArg

decompiled_code:
__int64 __fastcall findArg(char *a1, char *a2, __int64 *a3)
{
char *v4; // rbx
size_t v5; // rax

if ( a3 == 0LL || a2 == 0LL )
return 0LL;
if ( !a1 )
return 0LL;
v4 = findKey(a1, a2);
if ( !v4 )
return 0LL;
v5 = strlen(a2);
return getValue((__int64)&v4[v5], a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, char *a2, __int64 *a3)
{
char *v4; // rbx
size_t v5; // rax

if ( a3 == 0LL || a2 == 0LL )
return 0LL;
if ( !a1 )
return 0LL;
v4 = func1(a1, a2);
if ( !v4 )
return 0LL;
v5 = strlen(a2);
return func2((__int64)&v4[v5], a3);
}

original_code:
const char * findArg( const char * in_args, const char * in_key, size_t * out_size ) {
 if( ! in_args || ! in_key || ! out_size ) {
  return ((void *)0);
 }
 const char * key = findKey( in_args, in_key );
 if( ! key ) {
  out_size = 0;
  return ((void *)0);
 } else {
  return getValue( key + strlen( in_key ), out_size );
 }
}

canonical_original_code:
char *findArg(char *in_args, char *in_key, unsigned long *out_size) {
 if( ! in_args || ! in_key || ! out_size ) {
  return ((void *)0);
 }
 char *key = findKey( in_args, in_key );
 if( ! key ) {
  out_size = 0;
  return ((void *)0);
 } else {
  return getValue( key + strlen( in_key ), out_size );
 }
}

variable_types:
key
char *


reallocLogFD

decompiled_code:
__int64 __fastcall reallocLogFD(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rax
char *v5; // r14
__int64 v6; // rbx
int v7; // eax

v2 = defaultVtable[3]();
v3 = _tls_get_addr(&externalCall_tlsind);
if ( *((_BYTE *)reallocLogFD + v3) )
{
v5 = (char *)&textBuf + v3 - 1127;
v6 = v3;
*((_BYTE *)reallocLogFD + v3) = 0;
v7 = snprintf(v5, 0x3E8uLL, "realloc\t%llX\t%llu\t%llx\n", a1, a2, v2);
write(logFD, v5, v7);
*((_BYTE *)reallocLogFD + v6) = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rax
char *v5; // r14
__int64 v6; // rbx
int v7; // eax

v2 = defaultVtable[3]();
v3 = _tls_get_addr(&externalCall_tlsind);
if ( *((_BYTE *)reallocLogFD + v3) )
{
v5 = (char *)&textBuf + v3 - 1127;
v6 = v3;
*((_BYTE *)reallocLogFD + v3) = 0;
v7 = snprintf(v5, 0x3E8uLL, "realloc\t%llX\t%llu\t%llx\n", a1, a2, v2);
write(logFD, v5, v7);
*((_BYTE *)reallocLogFD + v6) = 1;
}
return v2;
}

original_code:
static void * reallocLogFD( void * in_ptr, size_t in_size ) {
 void * ret = defaultVtable.realloc( in_ptr, in_size );
 if( externalCall ) {
  externalCall = 0;
  int msgSize = snprintf( textBuf, textBufSize, "realloc\t%llX\t%llu\t%llx\n", (unsigned long long)(size_t) in_ptr, (unsigned long long) in_size, (unsigned long long)(size_t) ret );
  write( logFD, textBuf, msgSize );
  externalCall = 1;
 }
 return ret;
}

canonical_original_code:
static void *reallocLogFD(void *in_ptr, unsigned long in_size) {
 void *ret = defaultVtable.realloc( in_ptr, in_size );
 if( externalCall ) {
  externalCall = 0;
  int msgSize = snprintf( textBuf, textBufSize, "realloc\t%llX\t%llu\t%llx\n", (unsigned long long)(size_t) in_ptr, (unsigned long long) in_size, (unsigned long long)(size_t) ret );
  write( logFD, textBuf, msgSize );
  externalCall = 1;
 }
 return ret;
}

variable_types:
ret
void *

variable_types: msgSize int

return_type: void *


callocLogFD

decompiled_code:
__int64 __fastcall callocLogFD(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rax
char *v5; // r14
__int64 v6; // rbx
int v7; // eax

v2 = defaultVtable[2]();
v3 = _tls_get_addr(&externalCall_tlsind);
if ( *((_BYTE *)reallocLogFD + v3) )
{
v5 = (char *)&textBuf + v3 - 1127;
v6 = v3;
*((_BYTE *)reallocLogFD + v3) = 0;
v7 = snprintf(v5, 0x3E8uLL, "calloc\t%llu\t%llu\t%llx\n", a1, a2, v2);
write(logFD, v5, v7);
*((_BYTE *)reallocLogFD + v6) = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rax
char *v5; // r14
__int64 v6; // rbx
int v7; // eax

v2 = defaultVtable[2]();
v3 = _tls_get_addr(&externalCall_tlsind);
if ( *((_BYTE *)reallocLogFD + v3) )
{
v5 = (char *)&textBuf + v3 - 1127;
v6 = v3;
*((_BYTE *)reallocLogFD + v3) = 0;
v7 = snprintf(v5, 0x3E8uLL, "calloc\t%llu\t%llu\t%llx\n", a1, a2, v2);
write(logFD, v5, v7);
*((_BYTE *)reallocLogFD + v6) = 1;
}
return v2;
}

original_code:
static void * callocLogFD( size_t in_qty, size_t in_size ) {
 void * ret = defaultVtable.calloc( in_qty, in_size );
 if( externalCall ) {
  externalCall = 0;
  int msgSize = snprintf( textBuf, textBufSize, "calloc\t%llu\t%llu\t%llx\n", (unsigned long long) in_qty, (unsigned long long) in_size, (unsigned long long)(size_t) ret );
  write( logFD, textBuf, msgSize );
  externalCall = 1;
 }
 return ret;
}

canonical_original_code:
static void *callocLogFD(unsigned long in_qty, unsigned long in_size) {
 void *ret = defaultVtable.calloc( in_qty, in_size );
 if( externalCall ) {
  externalCall = 0;
  int msgSize = snprintf( textBuf, textBufSize, "calloc\t%llu\t%llu\t%llx\n", (unsigned long long) in_qty, (unsigned long long) in_size, (unsigned long long)(size_t) ret );
  write( logFD, textBuf, msgSize );
  externalCall = 1;
 }
 return ret;
}


freeLogFD

decompiled_code:
ssize_t __fastcall freeLogFD(__int64 a1)
{
ssize_t result; // rax
char *v2; // rbp
ssize_t v3; // rbx
int v4; // eax

defaultVtable[1]();
result = _tls_get_addr(&externalCall_tlsind);
if ( *((_BYTE *)reallocLogFD + result) )
{
v2 = (char *)&textBuf + result - 1127;
v3 = result;
*((_BYTE *)reallocLogFD + result) = 0;
v4 = snprintf(v2, 0x3E8uLL, "free\t%llX\n", a1);
result = write(logFD, v2, v4);
*((_BYTE *)reallocLogFD + v3) = 1;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(__int64 a1)
{
ssize_t result; // rax
char *v2; // rbp
ssize_t v3; // rbx
int v4; // eax

defaultVtable[1]();
result = _tls_get_addr(&externalCall_tlsind);
if ( *((_BYTE *)reallocLogFD + result) )
{
v2 = (char *)&textBuf + result - 1127;
v3 = result;
*((_BYTE *)reallocLogFD + result) = 0;
v4 = snprintf(v2, 0x3E8uLL, "free\t%llX\n", a1);
result = write(logFD, v2, v4);
*((_BYTE *)reallocLogFD + v3) = 1;
}
return result;
}

original_code:
static void freeLogFD( void * in_ptr ) {
 defaultVtable.free( in_ptr );
 if( externalCall ) {
  externalCall = 0;
  int msgSize = snprintf( textBuf, textBufSize, "free\t%llX\n", (unsigned long long)(size_t) in_ptr );
  write( logFD, textBuf, msgSize );
  externalCall = 1;
 }
}

canonical_original_code:
static void freeLogFD(void *in_ptr) {
 defaultVtable.free( in_ptr );
 if( externalCall ) {
  externalCall = 0;
  int msgSize = snprintf( textBuf, textBufSize, "free\t%llX\n", (unsigned long long)(size_t) in_ptr );
  write( logFD, textBuf, msgSize );
  externalCall = 1;
 }
}


mallocLogFD

decompiled_code:
__int64 __fastcall mallocLogFD(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rax
char *v4; // rbp
__int64 v5; // rbx
int v6; // eax

v1 = defaultVtable[0]();
v2 = _tls_get_addr(&externalCall_tlsind);
if ( *((_BYTE *)reallocLogFD + v2) )
{
v4 = (char *)&textBuf + v2 - 1127;
v5 = v2;
*((_BYTE *)reallocLogFD + v2) = 0;
v6 = snprintf(v4, 0x3E8uLL, "malloc\t%llu\t%llX\n", a1, v1);
write(logFD, v4, v6);
*((_BYTE *)reallocLogFD + v5) = 1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rax
char *v4; // rbp
__int64 v5; // rbx
int v6; // eax

v1 = defaultVtable[0]();
v2 = _tls_get_addr(&externalCall_tlsind);
if ( *((_BYTE *)reallocLogFD + v2) )
{
v4 = (char *)&textBuf + v2 - 1127;
v5 = v2;
*((_BYTE *)reallocLogFD + v2) = 0;
v6 = snprintf(v4, 0x3E8uLL, "malloc\t%llu\t%llX\n", a1, v1);
write(logFD, v4, v6);
*((_BYTE *)reallocLogFD + v5) = 1;
}
return v1;
}

original_code:
static void * mallocLogFD( size_t in_size ) {
 void * ret = defaultVtable.malloc( in_size );
 if( externalCall ) {
  externalCall = 0;
  int msgSize = snprintf( textBuf, textBufSize, "malloc\t%llu\t%llX\n", (unsigned long long) in_size, (unsigned long long)(size_t) ret );
  write( logFD, textBuf, msgSize );
  externalCall = 1;
 }
 return ret;
}

canonical_original_code:
static void *mallocLogFD(unsigned long in_size) {
 void *ret = defaultVtable.malloc( in_size );
 if( externalCall ) {
  externalCall = 0;
  int msgSize = snprintf( textBuf, textBufSize, "malloc\t%llu\t%llX\n", (unsigned long long) in_size, (unsigned long long)(size_t) ret );
  write( logFD, textBuf, msgSize );
  externalCall = 1;
 }
 return ret;
}


mprofLogFDSet

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

result = (unsigned int)logFD;
logFD = a1;
return result;
}

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

result = (unsigned int)logFD;
logFD = a1;
return result;
}

original_code:
int mprofLogFDSet( int in_fd ) {
 int ret = logFD;
 logFD = in_fd;
 return ret;
}

canonical_original_code:
int mprofLogFDSet(int in_fd) {
 int ret = logFD;
 logFD = in_fd;
 return ret;
}

variable_types: ret int


mprofCountDestruct

decompiled_code:
__int64 mprofCountDestruct()
{
sem_destroy(&mmapSem);
return mmapClose(&countsArea);
}

canonical_decompiled_code:
__int64 func0()
{
sem_destroy(&mmapSem);
return mmapClose(&countsArea);
}

original_code:
static void mprofCountDestruct( void ) {
 sem_destroy( &mmapSem );
 mmapClose( &countsArea );
}

canonical_original_code:
static void mprofCountDestruct() {
 sem_destroy( &mmapSem );
 mmapClose( &countsArea );
}


mprofCountConstruct

decompiled_code:
__int64 mprofCountConstruct()
{
char *v0; // rbp
__int64 v1; // rax
__int64 v2; // rax
const char *v3; // rsi
__int64 result; // rax
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = "./mprof.counts";
v1 = getConfStr();
v2 = findArg(v1, "COUNTS_PATH", n);
if ( v2 )
{
v3 = (const char *)v2;
v0 = (char *)tmpAllocVtable[2](n[0] + 1, 1LL);
strncpy(v0, v3, n[0]);
}
mprofRecordInit();
sem_init(&mmapSem, 0, 1u);
if ( !(unsigned __int8)mmapOpen(&countsArea, v0, 578LL) )
_assert_fail(
"mmapOpen( &countsArea, value, O_RDWR | O_TRUNC | O_CREAT )",
"src/mprofCount.c",
0x34u,
"mprofCountConstruct");
result = mmapSize(&countsArea, 40LL, 0LL);
if ( !(_BYTE)result )
_assert_fail(
"mmapSize( &countsArea, sizeof( struct MprofRecordCount ), MMAP_AREA_SET )",
"src/mprofCount.c",
0x35u,
"mprofCountConstruct");
return result;
}

canonical_decompiled_code:
__int64 func1()
{
char *v0; // rbp
__int64 v1; // rax
__int64 v2; // rax
const char *v3; // rsi
__int64 result; // rax
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = "./mprof.counts";
v1 = getConfStr();
v2 = findArg(v1, "COUNTS_PATH", n);
if ( v2 )
{
v3 = (const char *)v2;
v0 = (char *)tmpAllocVtable[2](n[0] + 1, 1LL);
strncpy(v0, v3, n[0]);
}
mprofRecordInit();
sem_init(&mmapSem, 0, 1u);
if ( !(unsigned __int8)mmapOpen(&countsArea, v0, 578LL) )
_assert_fail(
"mmapOpen( &countsArea, value, O_RDWR | O_TRUNC | O_CREAT )",
"src/mprofCount.c",
0x34u,
"mprofCountConstruct");
result = mmapSize(&countsArea, 40LL, 0LL);
if ( !(_BYTE)result )
_assert_fail(
"mmapSize( &countsArea, sizeof( struct MprofRecordCount ), MMAP_AREA_SET )",
"src/mprofCount.c",
0x35u,
"mprofCountConstruct");
return result;
}

original_code:
static void mprofCountConstruct( void ) {
 size_t valueSize;
 const char * value = findArg( getConfStr(), "COUNTS_PATH", &valueSize );
 if( value ) {
  char * tmp = tmpAllocVtable.calloc( valueSize + 1, sizeof( char ) );
  strncpy( tmp, value, valueSize );
  value = tmp;
 } else {
  value = "./mprof.counts";
 }
 mprofRecordInit();
 sem_init( &mmapSem, 0, 1 );
 ((mmapOpen( &countsArea, value, 02 | 01000 | 0100 )) ? (void) (0) : __assert_fail ("mmapOpen( &countsArea, value, O_RDWR | O_TRUNC | O_CREAT )", "src/mprofCount.c", 52, __extension__ __PRETTY_FUNCTION__));
 ((mmapSize( &countsArea, sizeof( struct MprofRecordCount ), ( 0 ) )) ? (void) (0) : __assert_fail ("mmapSize( &countsArea, sizeof( struct MprofRecordCount ), MMAP_AREA_SET )", "src/mprofCount.c", 53, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
static void mprofCountConstruct() {
 unsigned long valueSize;
 char *value = findArg( getConfStr(), "COUNTS_PATH", &valueSize );
 if( value ) {
  char *tmp = tmpAllocVtable.calloc( valueSize + 1, sizeof( char ) );
  strncpy( tmp, value, valueSize );
  value = tmp;
 } else {
  value = "./mprof.counts";
 }
 mprofRecordInit();
 sem_init( &mmapSem, 0, 1 );
 ((mmapOpen( &countsArea, value, 02 | 01000 | 0100 )) ? (void) (0) : __assert_fail ("mmapOpen( &countsArea, value, O_RDWR | O_TRUNC | O_CREAT )", "src/mprofCount.c", 52, __extension__ __PRETTY_FUNCTION__));
 ((mmapSize( &countsArea, sizeof( struct MprofRecordCount ), ( 0 ) )) ? (void) (0) : __assert_fail ("mmapSize( &countsArea, sizeof( struct MprofRecordCount ), MMAP_AREA_SET )", "src/mprofCount.c", 53, __extension__ __PRETTY_FUNCTION__));
}

variable_types:
value
char *

variable_types:
tmp
char *

user_defined_types: struct MprofRecordCount { struct MprofRecordHeader header; unsigned short thread; unsigned short padding[2]; unsigned long malloc; unsigned long free; unsigned long calloc; unsigned long realloc; }

user_defined_types: struct MprofRecordHeader { unsigned char mode; unsigned char flags; }


mprofCountThreadInit

decompiled_code:
__int64 *mprofCountThreadInit()
{
__int64 *result; // rax
signed __int64 v1; // rbp
unsigned __int64 v2; // rbx
__int64 v3; // rbx

result = (__int64 *)_tls_get_addr(&mprofLocalCounts_tlsind);
if ( !*result )
{
v1 = _InterlockedExchangeAdd64(threadID, 1uLL);
v2 = 8 * (5 * v1 + 5);
if ( qword_368 < v2 )
{
sem_wait(&mmapSem);
if ( qword_368 < v2 && !(unsigned __int8)mmapSize(&countsArea, 8 * (5 * v1 + 5), 0LL) )
_assert_fail(
"mmapSize( &countsArea, minSize, MMAP_AREA_SET )",
"src/mprofCount.c",
0x47u,
"mprofCountThreadInit");
sem_post(&mmapSem);
}
v3 = qword_370 + v2 - 40;
result = (__int64 *)_tls_get_addr(&mprofLocalCounts_tlsind);
*result = v3;
*(_BYTE *)v3 = 5;
*(_WORD *)(v3 + 2) = v1;
}
return result;
}

canonical_decompiled_code:
__int64 *func2()
{
__int64 *result; // rax
signed __int64 v1; // rbp
unsigned __int64 v2; // rbx
__int64 v3; // rbx

result = (__int64 *)_tls_get_addr(&mprofLocalCounts_tlsind);
if ( !*result )
{
v1 = _InterlockedExchangeAdd64(threadID, 1uLL);
v2 = 8 * (5 * v1 + 5);
if ( qword_368 < v2 )
{
sem_wait(&mmapSem);
if ( qword_368 < v2 && !(unsigned __int8)mmapSize(&countsArea, 8 * (5 * v1 + 5), 0LL) )
_assert_fail(
"mmapSize( &countsArea, minSize, MMAP_AREA_SET )",
"src/mprofCount.c",
0x47u,
"mprofCountThreadInit");
sem_post(&mmapSem);
}
v3 = qword_370 + v2 - 40;
result = (__int64 *)_tls_get_addr(&mprofLocalCounts_tlsind);
*result = v3;
*(_BYTE *)v3 = 5;
*(_WORD *)(v3 + 2) = v1;
}
return result;
}

original_code:
static void mprofCountThreadInit( void ) {
 if( mprofLocalCounts == ((void *)0) ) {
  size_t mmapIndex = __sync_fetch_and_add( &threadID, 1 );
  const size_t minSize = ( 1 + mmapIndex ) * sizeof( struct MprofRecordCount );
  if( minSize > countsArea.fileSize ) {
   sem_wait( &mmapSem );
   if( minSize > countsArea.fileSize ) {
    ((mmapSize( &countsArea, minSize, ( 0 ) )) ? (void) (0) : __assert_fail ("mmapSize( &countsArea, minSize, MMAP_AREA_SET )", "src/mprofCount.c", 71, __extension__ __PRETTY_FUNCTION__));
   }
   sem_post( &mmapSem );
  }
  mprofLocalCounts = ( (struct MprofRecordCount *) countsArea.base ) + mmapIndex;
  mprofLocalCounts->header.mode = ( 5u );
  mprofLocalCounts->thread = mmapIndex;
 }
}

canonical_original_code:
static void mprofCountThreadInit() {
 if( mprofLocalCounts == ((void *)0) ) {
  unsigned long mmapIndex = __sync_fetch_and_add( &threadID, 1 );
  unsigned long minSize = ( 1 + mmapIndex ) * sizeof( struct MprofRecordCount );
  if( minSize > countsArea.fileSize ) {
   sem_wait( &mmapSem );
   if( minSize > countsArea.fileSize ) {
    ((mmapSize( &countsArea, minSize, ( 0 ) )) ? (void) (0) : __assert_fail ("mmapSize( &countsArea, minSize, MMAP_AREA_SET )", "src/mprofCount.c", 71, __extension__ __PRETTY_FUNCTION__));
   }
   sem_post( &mmapSem );
  }
  mprofLocalCounts = ( (struct MprofRecordCount *) countsArea.base ) + mmapIndex;
  mprofLocalCounts->header.mode = ( 5u );
  mprofLocalCounts->thread = mmapIndex;
 }
}

variable_types:
mmapIndex
unsigned long

variable_types:
minSize
unsigned long


reallocCount

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

mprofCountThreadInit();
v2 = _tls_get_addr(&mprofLocalCounts_tlsind);
++*(_QWORD *)(*(_QWORD *)v2 + 32LL);
return defaultVtable[3](a1, a2);
}

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

func2();
v2 = _tls_get_addr(&mprofLocalCounts_tlsind);
++*(_QWORD *)(*(_QWORD *)v2 + 32LL);
return defaultVtable[3](a1, a2);
}

original_code:
static void * reallocCount( void * in_ptr, size_t in_size ) {
 mprofCountThreadInit();
 mprofLocalCounts->realloc += 1;
 return defaultVtable.realloc( in_ptr, in_size );
}

canonical_original_code:
static void *reallocCount(void *in_ptr, unsigned long in_size) {
 mprofCountThreadInit();
 mprofLocalCounts->realloc += 1;
 return defaultVtable.realloc( in_ptr, in_size );
}


callocCount

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

mprofCountThreadInit();
v2 = _tls_get_addr(&mprofLocalCounts_tlsind);
++*(_QWORD *)(*(_QWORD *)v2 + 24LL);
return defaultVtable[2](a1, a2);
}

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

func2();
v2 = _tls_get_addr(&mprofLocalCounts_tlsind);
++*(_QWORD *)(*(_QWORD *)v2 + 24LL);
return defaultVtable[2](a1, a2);
}

original_code:
static void * callocCount( size_t in_size, size_t in_qty ) {
 mprofCountThreadInit();
 mprofLocalCounts->calloc += 1;
 return defaultVtable.calloc( in_size, in_qty );
}

canonical_original_code:
static void *callocCount(unsigned long in_size, unsigned long in_qty) {
 mprofCountThreadInit();
 mprofLocalCounts->calloc += 1;
 return defaultVtable.calloc( in_size, in_qty );
}


freeCount

decompiled_code:
__int64 __fastcall freeCount(__int64 a1)
{
__int64 v1; // rax

mprofCountThreadInit();
v1 = _tls_get_addr(&mprofLocalCounts_tlsind);
++*(_QWORD *)(*(_QWORD *)v1 + 16LL);
return ((__int64 (__fastcall *)(__int64))defaultVtable[1])(a1);
}

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

func2();
v1 = _tls_get_addr(&mprofLocalCounts_tlsind);
++*(_QWORD *)(*(_QWORD *)v1 + 16LL);
return ((__int64 (__fastcall *)(__int64))defaultVtable[1])(a1);
}

original_code:
static void freeCount( void * in_ptr ) {
 mprofCountThreadInit();
 mprofLocalCounts->free += 1;
 defaultVtable.free( in_ptr );
}

canonical_original_code:
static void freeCount(void *in_ptr) {
 mprofCountThreadInit();
 mprofLocalCounts->free += 1;
 defaultVtable.free( in_ptr );
}


mallocCount

decompiled_code:
__int64 __fastcall mallocCount(__int64 a1)
{
__int64 v1; // rax

mprofCountThreadInit();
v1 = _tls_get_addr(&mprofLocalCounts_tlsind);
++*(_QWORD *)(*(_QWORD *)v1 + 8LL);
return ((__int64 (__fastcall *)(__int64))defaultVtable[0])(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rax

func2();
v1 = _tls_get_addr(&mprofLocalCounts_tlsind);
++*(_QWORD *)(*(_QWORD *)v1 + 8LL);
return ((__int64 (__fastcall *)(__int64))defaultVtable[0])(a1);
}

original_code:
static void * mallocCount( size_t in_size ) {
 mprofCountThreadInit();
 mprofLocalCounts->malloc += 1;
 return defaultVtable.malloc( in_size );
}

canonical_original_code:
static void *mallocCount(unsigned long in_size) {
 mprofCountThreadInit();
 mprofLocalCounts->malloc += 1;
 return defaultVtable.malloc( in_size );
}


mprofLogMmapDestruct

decompiled_code:
__int64 mprofLogMmapDestruct()
{
sem_destroy(&mmapSem);
return mmapClose(&area);
}

canonical_decompiled_code:
__int64 func0()
{
sem_destroy(&mmapSem);
return mmapClose(&area);
}

original_code:
static void mprofLogMmapDestruct( void ) {
 sem_destroy( &mmapSem );
 mmapClose( &area );
}

canonical_original_code:
static void mprofLogMmapDestruct() {
 sem_destroy( &mmapSem );
 mmapClose( &area );
}


mprofLogMmapConstruct

decompiled_code:
int mprofLogMmapConstruct()
{
__int64 v0; // rax
const char *v1; // rax
__int64 v2; // rax
const char *v3; // rdi
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
char *v8; // r8
const char *v9; // rbp
char *v10; // rax
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = ((__int64 (*)(void))getConfStr)();
v1 = (const char *)findArg(v0, "LOG_QTY", n);
if ( v1 )
growthQty = (void *)strtol(v1, 0LL, 10);
v2 = ((__int64 (*)(void))getConfStr)();
v3 = (const char *)findArg(v2, "CACHE_QTY", n);
if ( v3 )
cacheQty = strtol(v3, 0LL, 10);
v4 = getConfStr(v3);
v5 = findArg(v4, "LOG_PATH", n);
v8 = "./mprof.log";
v9 = (const char *)v5;
if ( v5 )
{
v10 = (char *)tmpAllocVtable[2](n[0] + 1, 1LL, v6, v7, "./mprof.log");
v8 = strncpy(v10, v9, n[0]);
}
if ( !(unsigned __int8)mmapOpen(&area, v8, 578LL) )
_assert_fail(
"mmapOpen( &area, arg, O_RDWR | O_TRUNC | O_CREAT )",
"src/mprofLogMmap.c",
0x4Eu,
"mprofLogMmapConstruct");
if ( !(unsigned __int8)mmapSize(&area, 40LL * (_QWORD)growthQty, 0LL) )
_assert_fail(
"mmapSize( &area, growthQty * sizeof( struct MprofRecordAlloc ), MMAP_AREA_SET )",
"src/mprofLogMmap.c",
0x4Fu,
"mprofLogMmapConstruct");
return sem_init(&mmapSem, 0, 1u);
}

canonical_decompiled_code:
int func1()
{
__int64 v0; // rax
const char *v1; // rax
__int64 v2; // rax
const char *v3; // rdi
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
char *v8; // r8
const char *v9; // rbp
char *v10; // rax
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = ((__int64 (*)(void))getConfStr)();
v1 = (const char *)findArg(v0, "LOG_QTY", n);
if ( v1 )
growthQty = (void *)strtol(v1, 0LL, 10);
v2 = ((__int64 (*)(void))getConfStr)();
v3 = (const char *)findArg(v2, "CACHE_QTY", n);
if ( v3 )
cacheQty = strtol(v3, 0LL, 10);
v4 = getConfStr(v3);
v5 = findArg(v4, "LOG_PATH", n);
v8 = "./mprof.log";
v9 = (const char *)v5;
if ( v5 )
{
v10 = (char *)tmpAllocVtable[2](n[0] + 1, 1LL, v6, v7, "./mprof.log");
v8 = strncpy(v10, v9, n[0]);
}
if ( !(unsigned __int8)mmapOpen(&area, v8, 578LL) )
_assert_fail(
"mmapOpen( &area, arg, O_RDWR | O_TRUNC | O_CREAT )",
"src/mprofLogMmap.c",
0x4Eu,
"mprofLogMmapConstruct");
if ( !(unsigned __int8)mmapSize(&area, 40LL * (_QWORD)growthQty, 0LL) )
_assert_fail(
"mmapSize( &area, growthQty * sizeof( struct MprofRecordAlloc ), MMAP_AREA_SET )",
"src/mprofLogMmap.c",
0x4Fu,
"mprofLogMmapConstruct");
return sem_init(&mmapSem, 0, 1u);
}

original_code:
static void mprofLogMmapConstruct( void ) {
 size_t argSize;
 const char * arg = findArg( getConfStr(), "LOG_QTY", &argSize );
 if( arg ) {
  growthQty = strtol( arg, ((void *)0), 10 );
 }
 arg = findArg( getConfStr(), "CACHE_QTY", &argSize );
 if( arg ) {
  cacheQty = strtol( arg, ((void *)0), 10 );
 }
 arg = findArg( getConfStr(), "LOG_PATH", &argSize );
 if( arg ) {
  char * tmp = tmpAllocVtable.calloc( argSize + 1, sizeof( char ) );
  strncpy( tmp, arg, argSize );
  arg = tmp;
 } else {
  arg = "./mprof.log";
 }
 ((mmapOpen( &area, arg, 02 | 01000 | 0100 )) ? (void) (0) : __assert_fail ("mmapOpen( &area, arg, O_RDWR | O_TRUNC | O_CREAT )", "src/mprofLogMmap.c", 78, __extension__ __PRETTY_FUNCTION__));
 ((mmapSize( &area, growthQty * sizeof( struct MprofRecordAlloc ), ( 0 ) )) ? (void) (0) : __assert_fail ("mmapSize( &area, growthQty * sizeof( struct MprofRecordAlloc ), MMAP_AREA_SET )", "src/mprofLogMmap.c", 79, __extension__ __PRETTY_FUNCTION__));
 sem_init( &mmapSem, 0, 1 );
}

canonical_original_code:
static void mprofLogMmapConstruct() {
 unsigned long argSize;
 char *arg = findArg( getConfStr(), "LOG_QTY", &argSize );
 if( arg ) {
  growthQty = strtol( arg, ((void *)0), 10 );
 }
 arg = findArg( getConfStr(), "CACHE_QTY", &argSize );
 if( arg ) {
  cacheQty = strtol( arg, ((void *)0), 10 );
 }
 arg = findArg( getConfStr(), "LOG_PATH", &argSize );
 if( arg ) {
  char *tmp = tmpAllocVtable.calloc( argSize + 1, sizeof( char ) );
  strncpy( tmp, arg, argSize );
  arg = tmp;
 } else {
  arg = "./mprof.log";
 }
 ((mmapOpen( &area, arg, 02 | 01000 | 0100 )) ? (void) (0) : __assert_fail ("mmapOpen( &area, arg, O_RDWR | O_TRUNC | O_CREAT )", "src/mprofLogMmap.c", 78, __extension__ __PRETTY_FUNCTION__));
 ((mmapSize( &area, growthQty * sizeof( struct MprofRecordAlloc ), ( 0 ) )) ? (void) (0) : __assert_fail ("mmapSize( &area, growthQty * sizeof( struct MprofRecordAlloc ), MMAP_AREA_SET )", "src/mprofLogMmap.c", 79, __extension__ __PRETTY_FUNCTION__));
 sem_init( &mmapSem, 0, 1 );
}

variable_types:
argSize
unsigned long

variable_types:
arg
char *

user_defined_types: struct MprofRecordAlloc { struct MprofRecordHeader header; unsigned short thread; unsigned long sec; unsigned int usec; union { struct MprofRecordMalloc malloc; struct MprofRecordFree free; struct MprofRecordRealloc realloc; struct MprofRecordCalloc calloc; } type; }

user_defined_types: struct MprofRecordMalloc { unsigned long size; unsigned long result; }

user_defined_types: struct MprofRecordFree { unsigned long pointer; }

user_defined_types: struct MprofRecordRealloc { unsigned long size; unsigned long pointer; unsigned long result; }

user_defined_types: struct MprofRecordCalloc { unsigned long size; unsigned long count; unsigned long result; }


populateCache

decompiled_code:
__int64 *populateCache()
{
signed __int64 v0; // rbx
__int64 v1; // r12
unsigned __int64 v2; // rbp
__int64 *result; // rax

v0 = _InterlockedExchangeAdd64((volatile signed __int64 *)&areaIndex, cacheQty);
v1 = cacheQty;
v2 = 40 * (cacheQty + v0);
if ( qword_498 < v2 )
{
sem_wait(&mmapSem);
if ( qword_498 < v2 && !(unsigned __int8)mmapSize(&area, v2 + 40LL * (_QWORD)growthQty, 0LL) )
_assert_fail(
"mmapSize( &area, requiredSize + growthQty * sizeof( struct MprofRecordAlloc ), MMAP_AREA_SET )",
"src/mprofLogMmap.c",
0x32u,
"populateCache");
sem_post(&mmapSem);
v1 = cacheQty;
}
*(_QWORD *)_tls_get_addr(&cache_tlsind) = qword_4A0 + 40 * v0;
result = (__int64 *)_tls_get_addr(&cacheRemaining_tlsind);
*result = v1;
return result;
}

canonical_decompiled_code:
__int64 *func2()
{
signed __int64 v0; // rbx
__int64 v1; // r12
unsigned __int64 v2; // rbp
__int64 *result; // rax

v0 = _InterlockedExchangeAdd64((volatile signed __int64 *)&areaIndex, cacheQty);
v1 = cacheQty;
v2 = 40 * (cacheQty + v0);
if ( qword_498 < v2 )
{
sem_wait(&mmapSem);
if ( qword_498 < v2 && !(unsigned __int8)mmapSize(&area, v2 + 40LL * (_QWORD)growthQty, 0LL) )
_assert_fail(
"mmapSize( &area, requiredSize + growthQty * sizeof( struct MprofRecordAlloc ), MMAP_AREA_SET )",
"src/mprofLogMmap.c",
0x32u,
"populateCache");
sem_post(&mmapSem);
v1 = cacheQty;
}
*(_QWORD *)_tls_get_addr(&cache_tlsind) = qword_4A0 + 40 * v0;
result = (__int64 *)_tls_get_addr(&cacheRemaining_tlsind);
*result = v1;
return result;
}

original_code:
static void populateCache( void ) {
 size_t index = __sync_fetch_and_add( &areaIndex, cacheQty );
 size_t requiredSize = ( index + cacheQty ) * sizeof( struct MprofRecordAlloc );
 if( requiredSize > area.fileSize ) {
  sem_wait( &mmapSem );
  if( requiredSize > area.fileSize ) {
   ((mmapSize( &area, requiredSize + growthQty * sizeof( struct MprofRecordAlloc ), ( 0 ) )) ? (void) (0) : __assert_fail ("mmapSize( &area, requiredSize + growthQty * sizeof( struct MprofRecordAlloc ), MMAP_AREA_SET )", "src/mprofLogMmap.c", 50, __extension__ __PRETTY_FUNCTION__));
  }
  sem_post( &mmapSem );
 }
 cache = ((struct MprofRecordAlloc *) area.base ) + index;
 cacheRemaining = cacheQty;
}

canonical_original_code:
static void populateCache() {
 unsigned long index = __sync_fetch_and_add( &areaIndex, cacheQty );
 unsigned long requiredSize = ( index + cacheQty ) * sizeof( struct MprofRecordAlloc );
 if( requiredSize > area.fileSize ) {
  sem_wait( &mmapSem );
  if( requiredSize > area.fileSize ) {
   ((mmapSize( &area, requiredSize + growthQty * sizeof( struct MprofRecordAlloc ), ( 0 ) )) ? (void) (0) : __assert_fail ("mmapSize( &area, requiredSize + growthQty * sizeof( struct MprofRecordAlloc ), MMAP_AREA_SET )", "src/mprofLogMmap.c", 50, __extension__ __PRETTY_FUNCTION__));
  }
  sem_post( &mmapSem );
 }
 cache = ((struct MprofRecordAlloc *) area.base ) + index;
 cacheRemaining = cacheQty;
}

variable_types:
index
unsigned long

variable_types:
requiredSize
unsigned long


reallocLogMmap

decompiled_code:
__int64 __fastcall reallocLogMmap(__int64 a1, __int64 a2)
{
__int64 v3; // r12
__int64 *v4; // rdx
__int64 v5; // rax
__int64 *v6; // rax
__int64 v7; // rdi

v3 = defaultVtable[3]();
v4 = (__int64 *)_tls_get_addr(&cacheRemaining_tlsind);
v5 = *v4 - 1;
*v4 = v5;
if ( !v5 )
populateCache();
v6 = (__int64 *)_tls_get_addr(&cache_tlsind);
v7 = *v6;
*(_QWORD *)(v7 + 16) = a2;
*(_QWORD *)(v7 + 24) = a1;
*(_QWORD *)(v7 + 32) = v3;
*(_BYTE *)v7 = 3;
*v6 = v7 + 40;
mprofRecordTimeStamp();
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v3; // r12
__int64 *v4; // rdx
__int64 v5; // rax
__int64 *v6; // rax
__int64 v7; // rdi

v3 = defaultVtable[3]();
v4 = (__int64 *)_tls_get_addr(&cacheRemaining_tlsind);
v5 = *v4 - 1;
*v4 = v5;
if ( !v5 )
func2();
v6 = (__int64 *)_tls_get_addr(&cache_tlsind);
v7 = *v6;
*(_QWORD *)(v7 + 16) = a2;
*(_QWORD *)(v7 + 24) = a1;
*(_QWORD *)(v7 + 32) = v3;
*(_BYTE *)v7 = 3;
*v6 = v7 + 40;
mprofRecordTimeStamp();
return v3;
}

original_code:
static void * reallocLogMmap( void * in_ptr, size_t in_size ) {
 void * ret = defaultVtable.realloc( in_ptr, in_size );
 if( --cacheRemaining == 0 ) {
  populateCache();
 }
 cache->type.realloc.size = in_size;
 cache->type.realloc.pointer = (size_t) in_ptr;
 cache->type.realloc.result = (size_t) ret;
 cache->header.mode = ( 3u );
 mprofRecordTimeStamp( cache++ );
 return ret;
}

canonical_original_code:
static void *reallocLogMmap(void *in_ptr, unsigned long in_size) {
 void *ret = defaultVtable.realloc( in_ptr, in_size );
 if( --cacheRemaining == 0 ) {
  populateCache();
 }
 cache->type.realloc.size = in_size;
 cache->type.realloc.pointer = (unsigned long) in_ptr;
 cache->type.realloc.result = (unsigned long) ret;
 cache->header.mode = ( 3u );
 mprofRecordTimeStamp( cache++ );
 return ret;
}


callocLogMmap

decompiled_code:
__int64 __fastcall callocLogMmap(__int64 a1, __int64 a2)
{
__int64 v3; // r12
__int64 *v4; // rdx
__int64 v5; // rax
__int64 *v6; // rax
__int64 v7; // rdi

v3 = defaultVtable[2]();
v4 = (__int64 *)_tls_get_addr(&cacheRemaining_tlsind);
v5 = *v4 - 1;
*v4 = v5;
if ( !v5 )
populateCache();
v6 = (__int64 *)_tls_get_addr(&cache_tlsind);
v7 = *v6;
*(_QWORD *)(v7 + 16) = a2;
*(_QWORD *)(v7 + 24) = a1;
*(_QWORD *)(v7 + 32) = v3;
*(_BYTE *)v7 = 4;
*v6 = v7 + 40;
mprofRecordTimeStamp();
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v3; // r12
__int64 *v4; // rdx
__int64 v5; // rax
__int64 *v6; // rax
__int64 v7; // rdi

v3 = defaultVtable[2]();
v4 = (__int64 *)_tls_get_addr(&cacheRemaining_tlsind);
v5 = *v4 - 1;
*v4 = v5;
if ( !v5 )
func2();
v6 = (__int64 *)_tls_get_addr(&cache_tlsind);
v7 = *v6;
*(_QWORD *)(v7 + 16) = a2;
*(_QWORD *)(v7 + 24) = a1;
*(_QWORD *)(v7 + 32) = v3;
*(_BYTE *)v7 = 4;
*v6 = v7 + 40;
mprofRecordTimeStamp();
return v3;
}

original_code:
static void * callocLogMmap( size_t in_qty, size_t in_size ) {
 void * ret = defaultVtable.calloc( in_qty, in_size );
 if( --cacheRemaining == 0 ) {
  populateCache();
 }
 cache->type.calloc.size = in_size;
 cache->type.calloc.count = in_qty;
 cache->type.calloc.result = (size_t) ret;
 cache->header.mode = ( 4u );
 mprofRecordTimeStamp( cache++ );
 return ret;
}

canonical_original_code:
static void *callocLogMmap(unsigned long in_qty, unsigned long in_size) {
 void *ret = defaultVtable.calloc( in_qty, in_size );
 if( --cacheRemaining == 0 ) {
  populateCache();
 }
 cache->type.calloc.size = in_size;
 cache->type.calloc.count = in_qty;
 cache->type.calloc.result = (unsigned long) ret;
 cache->header.mode = ( 4u );
 mprofRecordTimeStamp( cache++ );
 return ret;
}


freeLogMmap

decompiled_code:
__int64 __fastcall freeLogMmap(__int64 a1)
{
__int64 *v2; // rdx
__int64 v3; // rax
__int64 *v4; // rax
__int64 v5; // rdi

defaultVtable[1]();
v2 = (__int64 *)_tls_get_addr(&cacheRemaining_tlsind);
v3 = *v2 - 1;
*v2 = v3;
if ( !v3 )
populateCache();
v4 = (__int64 *)_tls_get_addr(&cache_tlsind);
v5 = *v4;
*(_BYTE *)v5 = 2;
*(_QWORD *)(v5 + 16) = a1;
*v4 = v5 + 40;
return mprofRecordTimeStamp();
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 *v2; // rdx
__int64 v3; // rax
__int64 *v4; // rax
__int64 v5; // rdi

defaultVtable[1]();
v2 = (__int64 *)_tls_get_addr(&cacheRemaining_tlsind);
v3 = *v2 - 1;
*v2 = v3;
if ( !v3 )
func2();
v4 = (__int64 *)_tls_get_addr(&cache_tlsind);
v5 = *v4;
*(_BYTE *)v5 = 2;
*(_QWORD *)(v5 + 16) = a1;
*v4 = v5 + 40;
return mprofRecordTimeStamp();
}

original_code:
static void freeLogMmap( void * in_ptr ) {
 defaultVtable.free( in_ptr );
 if( --cacheRemaining == 0 ) {
  populateCache();
 }
 cache->type.free.pointer = (size_t) in_ptr;
 cache->header.mode = ( 2u );
 mprofRecordTimeStamp( cache++ );
}

canonical_original_code:
static void freeLogMmap(void *in_ptr) {
 defaultVtable.free( in_ptr );
 if( --cacheRemaining == 0 ) {
  populateCache();
 }
 cache->type.free.pointer = (unsigned long) in_ptr;
 cache->header.mode = ( 2u );
 mprofRecordTimeStamp( cache++ );
}


mallocLogMmap

decompiled_code:
__int64 __fastcall mallocLogMmap(__int64 a1)
{
__int64 v2; // r12
__int64 *v3; // rdx
__int64 v4; // rax
__int64 *v5; // rax
__int64 v6; // rdi

v2 = defaultVtable[0]();
v3 = (__int64 *)_tls_get_addr(&cacheRemaining_tlsind);
v4 = *v3 - 1;
*v3 = v4;
if ( !v4 )
populateCache();
v5 = (__int64 *)_tls_get_addr(&cache_tlsind);
v6 = *v5;
*(_QWORD *)(v6 + 16) = a1;
*(_QWORD *)(v6 + 24) = v2;
*(_BYTE *)v6 = 1;
*v5 = v6 + 40;
mprofRecordTimeStamp();
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v2; // r12
__int64 *v3; // rdx
__int64 v4; // rax
__int64 *v5; // rax
__int64 v6; // rdi

v2 = defaultVtable[0]();
v3 = (__int64 *)_tls_get_addr(&cacheRemaining_tlsind);
v4 = *v3 - 1;
*v3 = v4;
if ( !v4 )
func2();
v5 = (__int64 *)_tls_get_addr(&cache_tlsind);
v6 = *v5;
*(_QWORD *)(v6 + 16) = a1;
*(_QWORD *)(v6 + 24) = v2;
*(_BYTE *)v6 = 1;
*v5 = v6 + 40;
mprofRecordTimeStamp();
return v2;
}

original_code:
static void * mallocLogMmap( size_t in_size ) {
 void * ret = defaultVtable.malloc( in_size );
 if( --cacheRemaining == 0 ) {
  populateCache();
 }
 cache->type.malloc.size = in_size;
 cache->type.malloc.result = (size_t) ret;
 cache->header.mode = ( 1u );
 mprofRecordTimeStamp( cache++ );
 return ret;
}

canonical_original_code:
static void *mallocLogMmap(unsigned long in_size) {
 void *ret = defaultVtable.malloc( in_size );
 if( --cacheRemaining == 0 ) {
  populateCache();
 }
 cache->type.malloc.size = in_size;
 cache->type.malloc.result = (unsigned long) ret;
 cache->header.mode = ( 1u );
 mprofRecordTimeStamp( cache++ );
 return ret;
}


mprofLDInit

decompiled_code:
__int64 mprofLDInit()
{
__m128i v0; // xmm1
__m128i v1; // xmm2
__int64 v2; // rax
__int64 v3; // rax
const char *v4; // rax
void *v5; // rbp
char *v6; // r12
_QWORD *v7; // r14
const char **v8; // rbx
const char *v9; // r12
void *v10; // rax
__m128i v11; // xmm4
__m128i v12; // xmm5
__int64 result; // rax
size_t n[6]; // [rsp+8h] [rbp-30h] BYREF

v0 = _mm_loadu_si128((const __m128i *)&tmpAllocVtable + 1);
v1 = _mm_loadu_si128((const __m128i *)&tmpAllocVtable + 2);
v2 = *((_QWORD *)&tmpAllocVtable + 6);
mprofVtable = _mm_loadu_si128((const __m128i *)&tmpAllocVtable);
*((__m128i *)&mprofVtable + 1) = v0;
*((__m128i *)&mprofVtable + 2) = v1;
*((_QWORD *)&mprofVtable + 6) = v2;
v3 = getConfStr();
v4 = (const char *)findArg(v3, "LD_PRELOAD", n);
v5 = ldHandle;
if ( v4 )
{
v6 = strndup(v4, n[0]);
ldHandle = dlopen(v6, 265);
v5 = ldHandle;
if ( !ldHandle )
{
fprintf(
stderr,
"Error: libmprof: Could not open library '%s' specified for preload in env var 'MPROF_CONF'.\n",
v6);
LABEL_9:
exit(-1);
}
free(v6);
}
v7 = &defaultVtable;
v8 = (const char **)off_368;
v9 = "malloc";
do
{
v10 = dlsym(v5, v9);
if ( !v10 )
{
fprintf(stderr, "Error: libmprof: could not find original symbol '%s'\n", v9);
goto LABEL_9;
}
v9 = *v8;
*v7 = v10;
++v8;
++v7;
}
while ( v9 );
v11 = _mm_loadu_si128((const __m128i *)&postInitVtable + 1);
v12 = _mm_loadu_si128((const __m128i *)&postInitVtable + 2);
result = *((_QWORD *)&postInitVtable + 6);
mprofVtable = _mm_loadu_si128((const __m128i *)&postInitVtable);
*((_QWORD *)&mprofVtable + 6) = result;
*((__m128i *)&mprofVtable + 1) = v11;
*((__m128i *)&mprofVtable + 2) = v12;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__m128i v0; // xmm1
__m128i v1; // xmm2
__int64 v2; // rax
__int64 v3; // rax
const char *v4; // rax
void *v5; // rbp
char *v6; // r12
_QWORD *v7; // r14
const char **v8; // rbx
const char *v9; // r12
void *v10; // rax
__m128i v11; // xmm4
__m128i v12; // xmm5
__int64 result; // rax
size_t n[6]; // [rsp+8h] [rbp-30h] BYREF

v0 = _mm_loadu_si128((const __m128i *)&tmpAllocVtable + 1);
v1 = _mm_loadu_si128((const __m128i *)&tmpAllocVtable + 2);
v2 = *((_QWORD *)&tmpAllocVtable + 6);
mprofVtable = _mm_loadu_si128((const __m128i *)&tmpAllocVtable);
*((__m128i *)&mprofVtable + 1) = v0;
*((__m128i *)&mprofVtable + 2) = v1;
*((_QWORD *)&mprofVtable + 6) = v2;
v3 = getConfStr();
v4 = (const char *)findArg(v3, "LD_PRELOAD", n);
v5 = ldHandle;
if ( v4 )
{
v6 = strndup(v4, n[0]);
ldHandle = dlopen(v6, 265);
v5 = ldHandle;
if ( !ldHandle )
{
fprintf(
stderr,
"Error: libmprof: Could not open library '%s' specified for preload in env var 'MPROF_CONF'.\n",
v6);
LABEL_9:
exit(-1);
}
free(v6);
}
v7 = &defaultVtable;
v8 = (const char **)off_368;
v9 = "malloc";
do
{
v10 = dlsym(v5, v9);
if ( !v10 )
{
fprintf(stderr, "Error: libmprof: could not find original symbol '%s'\n", v9);
goto LABEL_9;
}
v9 = *v8;
*v7 = v10;
++v8;
++v7;
}
while ( v9 );
v11 = _mm_loadu_si128((const __m128i *)&postInitVtable + 1);
v12 = _mm_loadu_si128((const __m128i *)&postInitVtable + 2);
result = *((_QWORD *)&postInitVtable + 6);
mprofVtable = _mm_loadu_si128((const __m128i *)&postInitVtable);
*((_QWORD *)&mprofVtable + 6) = result;
*((__m128i *)&mprofVtable + 1) = v11;
*((__m128i *)&mprofVtable + 2) = v12;
return result;
}

original_code:
static void mprofLDInit( void ) {
 mprofVtable = tmpAllocVtable;
 size_t valueSize;
 const char * value = findArg( getConfStr(), "LD_PRELOAD", &valueSize );
 if( value ) {
  char * path = strndup( value, valueSize );
  ldHandle = dlopen( path, 0x00001 | 0x00100 | 0x00008 );
  if( ((void *)0) == ldHandle ) {
   fprintf( stderr, "Error: libmprof: Could not open library '%s' specified for preload in env var 'MPROF_CONF'.\n", path );
   exit( -1 );
  }
  free( path );
 }
 uint8_t * fnPtr = (uint8_t*) &defaultVtable.malloc;
 for( size_t index = 0; ldNames[ index ] != ((void *)0); index++ ) {
  void * result = dlsym( ldHandle, ldNames[ index ] );
  if( result ) {
   memcpy( &fnPtr[ index * sizeof( int(*)( void ) ) ], &result, sizeof( int(*)( void ) ) );
  } else {
   fprintf( stderr, "Error: libmprof: could not find original symbol '%s'\n", ldNames[ index ] );
   exit( -1 );
  }
 }
 mprofVtable = postInitVtable;
}

canonical_original_code:
static void mprofLDInit() {
 mprofVtable = tmpAllocVtable;
 unsigned long valueSize;
 char *value = findArg( getConfStr(), "LD_PRELOAD", &valueSize );
 if( value ) {
  char *path = strndup( value, valueSize );
  ldHandle = dlopen( path, 0x00001 | 0x00100 | 0x00008 );
  if( ((void *)0) == ldHandle ) {
   fprintf( stderr, "Error: libmprof: Could not open library '%s' specified for preload in env var 'MPROF_CONF'.\n", path );
   exit( -1 );
  }
  free( path );
 }
 unsigned char *fnPtr = (uint8_t*) &defaultVtable.malloc;
 for( unsigned long index = 0; ldNames[ index ] != ((void *)0); index++ ) {
  void *result = dlsym( ldHandle, ldNames[ index ] );
  if( result ) {
   memcpy( &fnPtr[ index * sizeof( int (*)() ) ], &result, sizeof( int (*)() ) );
  } else {
   fprintf( stderr, "Error: libmprof: could not find original symbol '%s'\n", ldNames[ index ] );
   exit( -1 );
  }
 }
 mprofVtable = postInitVtable;
}

variable_types:
path
char *

variable_types:
fnPtr
unsigned char *

variable_types:
result
void *


reallocLDInit

decompiled_code:
void __noreturn reallocLDInit()
{
perror("Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?");
exit(-1);
}

canonical_decompiled_code:
void __noreturn func1()
{
perror("Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?");
exit(-1);
}

original_code:
static void * reallocLDInit( __attribute__((unused)) void * in_ptr, __attribute__((unused)) size_t in_size ) {
 perror( "Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?" );
 exit( -1 );
 return ((void *)0);
}

canonical_original_code:
static void *reallocLDInit(void *in_ptr, unsigned long in_size) {
 perror( "Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?" );
 exit( -1 );
 return ((void *)0);
}


callocLDInit

decompiled_code:
void __noreturn callocLDInit()
{
perror("Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?");
exit(-1);
}

canonical_decompiled_code:
void __noreturn func2()
{
perror("Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?");
exit(-1);
}

original_code:
static void * callocLDInit( __attribute__((unused)) size_t in_size, __attribute__((unused)) size_t in_qty ) {
 perror( "Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?" );
 exit( -1 );
 return ((void *)0);
}

canonical_original_code:
static void *callocLDInit(unsigned long in_size, unsigned long in_qty) {
 perror( "Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?" );
 exit( -1 );
 return ((void *)0);
}


freeLDInit

decompiled_code:
void __noreturn freeLDInit()
{
perror("Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?");
exit(-1);
}

canonical_decompiled_code:
void __noreturn func3()
{
perror("Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?");
exit(-1);
}

original_code:
static void freeLDInit( __attribute__((unused)) void * in_ptr ) {
 perror( "Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?" );
 exit( -1 );
}

canonical_original_code:
static void freeLDInit(void *in_ptr) {
 perror( "Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?" );
 exit( -1 );
}


mallocLDInit

decompiled_code:
void __noreturn mallocLDInit()
{
perror("Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?");
exit(-1);
}

canonical_decompiled_code:
void __noreturn func4()
{
perror("Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?");
exit(-1);
}

original_code:
static void * mallocLDInit( __attribute__((unused)) size_t in_size ) {
 perror( "Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?" );
 exit( -1 );
 return ((void *)0);
}

canonical_original_code:
static void *mallocLDInit(unsigned long in_size) {
 perror( "Error: libmprof: race condition detected during LD init! Are you initializing in a multithreaded environment?" );
 exit( -1 );
 return ((void *)0);
}


mprofRecordTimeStamp

decompiled_code:
__suseconds_t __fastcall mprofRecordTimeStamp(__int64 a1)
{
__suseconds_t result; // rax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v2, 0LL);
*(_QWORD *)(a1 + 4) = v2.tv_sec;
result = v2.tv_usec;
*(_DWORD *)(a1 + 12) = v2.tv_usec;
return result;
}

canonical_decompiled_code:
__suseconds_t __fastcall func0(__int64 a1)
{
__suseconds_t result; // rax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v2, 0LL);
*(_QWORD *)(a1 + 4) = v2.tv_sec;
result = v2.tv_usec;
*(_DWORD *)(a1 + 12) = v2.tv_usec;
return result;
}

original_code:
void mprofRecordTimeStamp( struct MprofRecordAlloc * in_out_record ) {
 struct timeval tv;
 gettimeofday( &tv, ((void *)0) );
 in_out_record->sec = tv.tv_sec;
 in_out_record->usec = tv.tv_usec;
}

canonical_original_code:
void mprofRecordTimeStamp(struct MprofRecordAlloc *in_out_record) {
 struct timeval tv;
 gettimeofday( &tv, ((void *)0) );
 in_out_record->sec = tv.tv_sec;
 in_out_record->usec = tv.tv_usec;
}

variable_types: struct MprofRecordAlloc { struct MprofRecordHeader { unsigned char mode; unsigned char flags; } header; unsigned short thread; unsigned long sec; unsigned int usec; union { struct MprofRecordMalloc { unsigned long size; unsigned long result; } malloc; struct MprofRecordFree { unsigned long pointer; } free; struct MprofRecordRealloc { unsigned long size; unsigned long pointer; unsigned long result; } realloc; struct MprofRecordCalloc { unsigned long size; unsigned long count; unsigned long result; } calloc; } type; } *

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


mprofRecordInit

decompiled_code:
void mprofRecordInit()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void mprofRecordInit( void ) {
 ((sizeof( struct MprofRecordEmpty ) == sizeof( struct MprofRecordCount )) ? (void) (0) : __assert_fail ("sizeof( struct MprofRecordEmpty ) == sizeof( struct MprofRecordCount )", "src/mprofRecord.c", 67, __extension__ __PRETTY_FUNCTION__));
 ((sizeof( struct MprofRecordAlloc ) == sizeof( struct MprofRecordCount )) ? (void) (0) : __assert_fail ("sizeof( struct MprofRecordAlloc ) == sizeof( struct MprofRecordCount )", "src/mprofRecord.c", 68, __extension__ __PRETTY_FUNCTION__));
}

canonical_original_code:
void mprofRecordInit() {
 ((sizeof( struct MprofRecordEmpty ) == sizeof( struct MprofRecordCount )) ? (void) (0) : __assert_fail ("sizeof( struct MprofRecordEmpty ) == sizeof( struct MprofRecordCount )", "src/mprofRecord.c", 67, __extension__ __PRETTY_FUNCTION__));
 ((sizeof( struct MprofRecordAlloc ) == sizeof( struct MprofRecordCount )) ? (void) (0) : __assert_fail ("sizeof( struct MprofRecordAlloc ) == sizeof( struct MprofRecordCount )", "src/mprofRecord.c", 68, __extension__ __PRETTY_FUNCTION__));
}

user_defined_types: struct MprofRecordEmpty { struct MprofRecordHeader header; unsigned char padding[-1]; }


mmapOpen

decompiled_code:
__int64 __fastcall mmapOpen(__int64 a1, const char *a2, int a3)
{
char v3; // bp
int v5; // eax
void *v6; // rdi
__off_t v8; // rsi
void *v9; // rax
struct stat v10; // [rsp-30h] [rbp-A8h] BYREF

v3 = a3;
*(_QWORD *)(a1 + 16) = 0LL;
*(_OWORD *)a1 = 0LL;
v5 = open(a2, a3, 384LL);
*(_DWORD *)a1 = v5;
if ( v5 < 0 )
{
perror("mmapOpen: ");
v6 = *(void **)(a1 + 16);
LABEL_4:
if ( v6 )
munmap(v6, *(_QWORD *)(a1 + 8));
goto LABEL_6;
}
if ( fstat(v5, &v10) )
{
v6 = *(void **)(a1 + 16);
goto LABEL_4;
}
v8 = v10.st_size;
*(_QWORD *)(a1 + 8) = v10.st_size;
if ( v8 )
{
v9 = mmap(0LL, v8, (v3 & 2) == 0 ? 1 : 3, 1, *(_DWORD *)a1, 0LL);
if ( v9 == (void *)-1LL )
{
*(_QWORD *)(a1 + 16) = 0LL;
LABEL_6:
close(*(_DWORD *)a1);
*(_QWORD *)(a1 + 8) = 0LL;
return 0LL;
}
*(_QWORD *)(a1 + 16) = v9;
}
return 1LL;
}

original_code:
_Bool mmapOpen( struct mmapArea * out_area, const char * in_path, int in_openFlags ) {
 _Bool ret = 0;
 memset( out_area, 0, sizeof( struct mmapArea ) );
 do {
  out_area->fd = open( in_path, in_openFlags, 0400 | 0200 );
  if( out_area->fd < 0 ) {
   perror("mmapOpen: ");
   break;
  }
  struct stat st;
  if( fstat( out_area->fd, &st ) ) {
   break;
  }
  out_area->fileSize = st.st_size;
  int mmapProt = 0;
  if( ( ( ( in_openFlags ) & ( 02 ) ) == ( 02 ) ) ) {
   mmapProt |= 0x1 | 0x2;
  } else if( ( ( ( in_openFlags ) & ( 00 ) ) == ( 00 ) ) ) {
   mmapProt |= 0x1;
  } else if( ( ( ( in_openFlags ) & ( 01 ) ) == ( 01 ) ) ) {
   mmapProt |= 0x2;
  } else {
   fprintf( stderr, "mmapOpen: couldn't determine access mode for mapping\n" );
   break;
  }
  if( out_area->fileSize ) {
   out_area->base = mmap( ((void *)0), out_area->fileSize, mmapProt, 0x01, out_area->fd, 0 );
   if( out_area->base == (void*) -1 ) {
    out_area->base = ((void *)0);
    break;
   }
  }
  ret = 1;
 } while( 0 );
 if( 0 == ret ) {
  if( out_area->base ) {
   munmap( out_area->base, out_area->fileSize );
  }
  close( out_area->fd );
  out_area->fileSize = 0;
 }
 return ret;
}

canonical_original_code:
_Bool mmapOpen(struct mmapArea *out_area, char *in_path, int in_openFlags) {
 _Bool ret = 0;
 memset( out_area, 0, sizeof( struct mmapArea ) );
 do {
  out_area->fd = open( in_path, in_openFlags, 0400 | 0200 );
  if( out_area->fd < 0 ) {
   perror("mmapOpen: ");
   break;
  }
  struct stat st;
  if( fstat( out_area->fd, &st ) ) {
   break;
  }
  out_area->fileSize = st.st_size;
  int mmapProt = 0;
  if( ( ( ( in_openFlags ) & ( 02 ) ) == ( 02 ) ) ) {
   mmapProt |= 0x1 | 0x2;
  } else if( ( ( ( in_openFlags ) & ( 00 ) ) == ( 00 ) ) ) {
   mmapProt |= 0x1;
  } else if( ( ( ( in_openFlags ) & ( 01 ) ) == ( 01 ) ) ) {
   mmapProt |= 0x2;
  } else {
   fprintf( stderr, "mmapOpen: couldn't determine access mode for mapping\n" );
   break;
  }
  if( out_area->fileSize ) {
   out_area->base = mmap( ((void *)0), out_area->fileSize, mmapProt, 0x01, out_area->fd, 0 );
   if( out_area->base == (void *) -1 ) {
    out_area->base = ((void *)0);
    break;
   }
  }
  ret = 1;
 } while( 0 );
 if( 0 == ret ) {
  if( out_area->base ) {
   munmap( out_area->base, out_area->fileSize );
  }
  close( out_area->fd );
  out_area->fileSize = 0;
 }
 return ret;
}

variable_types: struct mmapArea { int fd; unsigned long fileSize; void *base; } *

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

variable_types: mmapProt int

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


mmapSize

decompiled_code:
__int64 __fastcall mmapSize(__int64 a1, size_t a2, int a3)
{
size_t v3; // rbp
__int64 result; // rax
size_t v6; // rdx
void *v7; // rdi
void *v8; // rax

v3 = a2;
if ( a3 )
{
result = 0LL;
if ( a3 != 2 )
return result;
v6 = *(_QWORD *)(a1 + 8);
if ( v6 < a2 )
return result;
v3 = v6 - a2;
}
if ( ftruncate(*(_DWORD *)a1, v3) )
{
perror("mmapSize: ftruncate:");
result = 0LL;
}
else
{
v7 = *(void **)(a1 + 16);
if ( v7 )
{
if ( *(void **)(a1 + 16) != mremap(v7, *(_QWORD *)(a1 + 8), v3, 0) )
{
perror("mmap:");
return 0LL;
}
goto LABEL_11;
}
v8 = mmap(0LL, v3, 3, 1, *(_DWORD *)a1, 0LL);
*(_QWORD *)(a1 + 16) = v8;
if ( v8 != (void *)-1LL )
{
LABEL_11:
*(_QWORD *)(a1 + 8) = v3;
return 1LL;
}
perror("mmap:");
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, size_t a2, int a3)
{
size_t v3; // rbp
__int64 result; // rax
size_t v6; // rdx
void *v7; // rdi
void *v8; // rax

v3 = a2;
if ( a3 )
{
result = 0LL;
if ( a3 != 2 )
return result;
v6 = *(_QWORD *)(a1 + 8);
if ( v6 < a2 )
return result;
v3 = v6 - a2;
}
if ( ftruncate(*(_DWORD *)a1, v3) )
{
perror("mmapSize: ftruncate:");
result = 0LL;
}
else
{
v7 = *(void **)(a1 + 16);
if ( v7 )
{
if ( *(void **)(a1 + 16) != mremap(v7, *(_QWORD *)(a1 + 8), v3, 0) )
{
perror("mmap:");
return 0LL;
}
goto LABEL_11;
}
v8 = mmap(0LL, v3, 3, 1, *(_DWORD *)a1, 0LL);
*(_QWORD *)(a1 + 16) = v8;
if ( v8 != (void *)-1LL )
{
LABEL_11:
*(_QWORD *)(a1 + 8) = v3;
return 1LL;
}
perror("mmap:");
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
}
return result;
}

original_code:
_Bool mmapSize( struct mmapArea * in_out_area, const size_t in_size, const int in_mode ) {
 _Bool ret = 0;
 do {
  size_t finalSize = 0;
  switch( in_mode ) {
  case ( ( 0 ) ):
   finalSize = in_size;
   ret = 1;
   break;
  case ( ( 1 ) ):
   finalSize = in_size + in_out_area->fileSize;
   break;
  case ( ( 2 ) ):
   if( in_size > in_out_area->fileSize ) {
    break;
   }
   finalSize = in_out_area->fileSize - in_size;
   ret = 1;
  default:
   break;
  }
  if( ! ret ) {
   break;
  } else {
   ret = 0;
  }
  if( ftruncate( in_out_area->fd, finalSize ) ) {
   perror( "mmapSize: ftruncate:" );
   break;
  }
  if( in_out_area->base ) {
   void * result = mremap( in_out_area->base, in_out_area->fileSize, finalSize, 0 );
   if( in_out_area->base != result ) {
    perror( "mmap:" );
    break;
   }
  } else {
   in_out_area->base = mmap( ((void *)0), finalSize, 0x1 | 0x2, 0x01, in_out_area->fd, 0 );
   if( (void*) -1 == in_out_area->base ) {
    perror( "mmap:" );
    in_out_area->base = ((void *)0);
    break;
   }
  }
  in_out_area->fileSize = finalSize;
  ret = 1;
 } while( 0 );
 return ret;
}

canonical_original_code:
_Bool mmapSize(struct mmapArea *in_out_area, unsigned long in_size, int in_mode) {
 _Bool ret = 0;
 do {
  unsigned long finalSize = 0;
  switch( in_mode ) {
  case ( ( 0 ) ):
   finalSize = in_size;
   ret = 1;
   break;
  case ( ( 1 ) ):
   finalSize = in_size + in_out_area->fileSize;
   break;
  case ( ( 2 ) ):
   if( in_size > in_out_area->fileSize ) {
    break;
   }
   finalSize = in_out_area->fileSize - in_size;
   ret = 1;
  default:
   break;
  }
  if( ! ret ) {
   break;
  } else {
   ret = 0;
  }
  if( ftruncate( in_out_area->fd, finalSize ) ) {
   perror( "mmapSize: ftruncate:" );
   break;
  }
  if( in_out_area->base ) {
   void *result = mremap( in_out_area->base, in_out_area->fileSize, finalSize, 0 );
   if( in_out_area->base != result ) {
    perror( "mmap:" );
    break;
   }
  } else {
   in_out_area->base = mmap( ((void *)0), finalSize, 0x1 | 0x2, 0x01, in_out_area->fd, 0 );
   if( (void *) -1 == in_out_area->base ) {
    perror( "mmap:" );
    in_out_area->base = ((void *)0);
    break;
   }
  }
  in_out_area->fileSize = finalSize;
  ret = 1;
 } while( 0 );
 return ret;
}

variable_types:
finalSize
unsigned long

user_defined_types: struct mmapArea { int fd; unsigned long fileSize; void *base; }


mmapClose

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

close(*(_DWORD *)a1);
result = munmap(*(void **)(a1 + 16), *(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}

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

close(*(_DWORD *)a1);
result = munmap(*(void **)(a1 + 16), *(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}

original_code:
void mmapClose( struct mmapArea * in_out_area ) {
 close( in_out_area->fd );
 munmap( in_out_area->base, in_out_area->fileSize );
 in_out_area->fileSize = 0;
}

canonical_original_code:
void mmapClose(struct mmapArea *in_out_area) {
 close( in_out_area->fd );
 munmap( in_out_area->base, in_out_area->fileSize );
 in_out_area->fileSize = 0;
}


freeTmpAlloc

decompiled_code:
void freeTmpAlloc()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code: static void freeTmpAlloc( __attribute__((unused)) void * in_ptr ) {}

canonical_original_code: static void freeTmpAlloc(void *in_ptr) {}


reallocTmpAlloc

decompiled_code:
__int64 reallocTmpAlloc()
{
perror("Warn: libmprof: TmpAlloc does not impliment realloc.");
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
perror("Warn: libmprof: TmpAlloc does not impliment realloc.");
return 0LL;
}

original_code:
static void * reallocTmpAlloc( __attribute__((unused)) void * in_ptr, __attribute__((unused)) size_t in_size ) {
 perror( "Warn: libmprof: TmpAlloc does not impliment realloc." );
 return ((void *)0);
}

canonical_original_code:
static void *reallocTmpAlloc(void *in_ptr, unsigned long in_size) {
 perror( "Warn: libmprof: TmpAlloc does not impliment realloc." );
 return ((void *)0);
}


mallocTmpAlloc

decompiled_code:
signed __int64 __fastcall mallocTmpAlloc(unsigned __int64 a1)
{
signed __int64 v1; // r8
signed __int64 result; // rax

if ( (unsigned __int64)tmpRemaining < a1 )
{
perror("ERROR: libmprof: mprofLDInit.c: tmp allocator out of space!");
result = 0LL;
}
else
{
v1 = (_UNKNOWN *)((char *)&unk_10BF + 1) - (_UNKNOWN *)tmpRemaining;
tmpRemaining = (char *)tmpRemaining - a1;
result = v1;
}
return result;
}

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

if ( (unsigned __int64)tmpRemaining < a1 )
{
perror("ERROR: libmprof: mprofLDInit.c: tmp allocator out of space!");
result = 0LL;
}
else
{
v1 = (_UNKNOWN *)((char *)&unk_10BF + 1) - (_UNKNOWN *)tmpRemaining;
tmpRemaining = (char *)tmpRemaining - a1;
result = v1;
}
return result;
}

original_code:
static void * mallocTmpAlloc( size_t in_size ) {
 if( in_size > tmpRemaining ) {
  perror( "ERROR: libmprof: mprofLDInit.c: tmp allocator out of space!" );
  return ((void *)0);
 } else {
  void * ret = &tmpBuf[ tmpSize - tmpRemaining ];
  tmpRemaining -= in_size;
  return ret;
 }
}

canonical_original_code:
static void *mallocTmpAlloc(unsigned long in_size) {
 if( in_size > tmpRemaining ) {
  perror( "ERROR: libmprof: mprofLDInit.c: tmp allocator out of space!" );
  return ((void *)0);
 } else {
  void *ret = &tmpBuf[ tmpSize - tmpRemaining ];
  tmpRemaining -= in_size;
  return ret;
 }
}

variable_types:
ret
void *


callocTmpAlloc

decompiled_code:
void *__fastcall callocTmpAlloc(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rsi
void *v3; // rax
void *v4; // r8

v2 = a1 * a2;
v3 = (void *)mallocTmpAlloc(v2);
v4 = v3;
if ( v3 )
v4 = memset(v3, 0, v2);
return v4;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rsi
void *v3; // rax
void *v4; // r8

v2 = a1 * a2;
v3 = (void *)func2(v2);
v4 = v3;
if ( v3 )
v4 = memset(v3, 0, v2);
return v4;
}

original_code:
static void * callocTmpAlloc( size_t in_qty, size_t in_size ) {
 in_size *= in_qty;
 void * ret = mallocTmpAlloc( in_size );
 if( ret ) {
  memset( ret, 0, in_size );
 }
 return ret;
}

canonical_original_code:
static void *callocTmpAlloc(unsigned long in_qty, unsigned long in_size) {
 in_size *= in_qty;
 void *ret = mallocTmpAlloc( in_size );
 if( ret ) {
  memset( ret, 0, in_size );
 }
 return ret;
}


tmpAllocRemaining

decompiled_code:
void *tmpAllocRemaining()
{
return tmpRemaining;
}

canonical_decompiled_code:
void *func4()
{
return tmpRemaining;
}

original_code: size_t tmpAllocRemaining( void ) { return tmpRemaining; }

canonical_original_code: unsigned long tmpAllocRemaining() { return tmpRemaining; }

return_type: unsigned long


repo: Alexanderbez/Multi-Merge-Sort

decompiled_code:
__int64 __fastcall int_cmp(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

original_code:
int int_cmp(const void *a, const void *b)
{
    int first = *(int *)a, second = *(int *)b;
    return first - second;
}

canonical_original_code:
int int_cmp(void *a, void *b)
{
    int first = *(int *)a; int second = *(int *)b;
    return first - second;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: first int

variable_types: second int


decompiled_code:
__int64 __fastcall tv_diff(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = a3 - a1;
if ( a4 - a2 < 0 )
--result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = a3 - a1;
if ( a4 - a2 < 0 )
--result;
return result;
}

original_code:
static struct timeval tv_diff(struct timeval start, struct timeval end)
{
    struct timeval delta = end;
    delta.tv_sec -= start.tv_sec;
    delta.tv_usec -= start.tv_usec;
    if (delta.tv_usec < 0) {
        delta.tv_usec += 1000000;
        delta.tv_sec--;
    }
    return delta;
}

variable_types:
start
struct timeval

variable_types:
end
struct timeval

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


main

canonical_name: main

original_code:
int main(int argc, char *argv[])
{
 int *ARRAY, *ARRAY_2, *ARRAY_3, *ARRAY_4, i, k;
 int num = atoi(argv[1]), seed = atoi(argv[2]), m_bound = atoi(argv[3]);
 struct rusage start_ru, end_ru;
   struct timeval start_wall, end_wall, diff_wall, diff_usr, diff_sys;
    Compare_fn cmp = int_cmp;
 ARRAY = malloc(sizeof(int) * num);
    ARRAY_2 = malloc(sizeof(int) * num);
    ARRAY_3 = malloc(sizeof(int) * num);
    ARRAY_4 = malloc(sizeof(int) * num);
 srand(seed);
 for (i = 0; i < num ; i ++)
    {
        k = rand() % m_bound;
  ARRAY[i] = k;
        ARRAY_2[i] = k;
        ARRAY_3[i] = k;
        ARRAY_4[i] = k;
    }
 gettimeofday(&start_wall, ((void *)0));
 getrusage(RUSAGE_SELF, &start_ru);
 mergesort(ARRAY, num, sizeof(int), cmp);
 gettimeofday(&end_wall, ((void *)0));
 getrusage(RUSAGE_SELF,&end_ru);
    diff_wall = tv_diff(start_wall, end_wall);
    diff_usr = tv_diff(start_ru.ru_utime, end_ru.ru_utime);
    diff_sys = tv_diff(start_ru.ru_stime, end_ru.ru_stime);
    printf("0 threads:  ");
    printf("%d.%06ds wall;  ", diff_wall.tv_sec, diff_wall.tv_usec);
    printf("%d.%06ds user;  ", diff_usr.tv_sec, diff_usr.tv_usec);
    printf("%d.%06ds sys\n", diff_sys.tv_sec, diff_sys.tv_usec);
 gettimeofday(&start_wall, ((void *)0));
 getrusage(RUSAGE_SELF, &start_ru);
 mt_mergesort(ARRAY_2, num, sizeof(int), cmp, 1);
 gettimeofday(&end_wall, ((void *)0));
 getrusage(RUSAGE_SELF,&end_ru);
    diff_wall = tv_diff(start_wall, end_wall);
    diff_usr = tv_diff(start_ru.ru_utime, end_ru.ru_utime);
    diff_sys = tv_diff(start_ru.ru_stime, end_ru.ru_stime);
    printf("1 threads:  ");
    printf("%d.%06ds wall;  ", diff_wall.tv_sec, diff_wall.tv_usec);
    printf("%d.%06ds user;  ", diff_usr.tv_sec, diff_usr.tv_usec);
    printf("%d.%06ds sys\n", diff_sys.tv_sec, diff_sys.tv_usec);
    gettimeofday(&start_wall, ((void *)0));
 getrusage(RUSAGE_SELF, &start_ru);
 mt_mergesort(ARRAY_3, num, sizeof(int), cmp, 2);
 gettimeofday(&end_wall, ((void *)0));
 getrusage(RUSAGE_SELF,&end_ru);
    diff_wall = tv_diff(start_wall, end_wall);
    diff_usr = tv_diff(start_ru.ru_utime, end_ru.ru_utime);
    diff_sys = tv_diff(start_ru.ru_stime, end_ru.ru_stime);
    printf("2 threads:  ");
    printf("%d.%06ds wall;  ", diff_wall.tv_sec, diff_wall.tv_usec);
    printf("%d.%06ds user;  ", diff_usr.tv_sec, diff_usr.tv_usec);
    printf("%d.%06ds sys\n", diff_sys.tv_sec, diff_sys.tv_usec);
    gettimeofday(&start_wall, ((void *)0));
 getrusage(RUSAGE_SELF, &start_ru);
 mt_mergesort(ARRAY_4, num, sizeof(int), cmp, 4);
 gettimeofday(&end_wall, ((void *)0));
 getrusage(RUSAGE_SELF,&end_ru);
    diff_wall = tv_diff(start_wall, end_wall);
    diff_usr = tv_diff(start_ru.ru_utime, end_ru.ru_utime);
    diff_sys = tv_diff(start_ru.ru_stime, end_ru.ru_stime);
    printf("4 threads:  ");
    printf("%d.%06ds wall;  ", diff_wall.tv_sec, diff_wall.tv_usec);
    printf("%d.%06ds user;  ", diff_usr.tv_sec, diff_usr.tv_usec);
    printf("%d.%06ds sys\n", diff_sys.tv_sec, diff_sys.tv_usec);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int *ARRAY; int *ARRAY_2; int *ARRAY_3; int *ARRAY_4; int i; int k;
 int num = atoi(argv[1]); int seed = atoi(argv[2]); int m_bound = atoi(argv[3]);
 struct rusage start_ru; struct rusage end_ru;
   struct timeval start_wall; struct timeval end_wall; struct timeval diff_wall; struct timeval diff_usr; struct timeval diff_sys;
    int (*cmp)(void *, void *) = int_cmp;
 ARRAY = malloc(sizeof(int) * num);
    ARRAY_2 = malloc(sizeof(int) * num);
    ARRAY_3 = malloc(sizeof(int) * num);
    ARRAY_4 = malloc(sizeof(int) * num);
 srand(seed);
 for (i = 0; i < num ; i ++)
    {
        k = rand() % m_bound;
  ARRAY[i] = k;
        ARRAY_2[i] = k;
        ARRAY_3[i] = k;
        ARRAY_4[i] = k;
    }
 gettimeofday(&start_wall, ((void *)0));
 getrusage(RUSAGE_SELF, &start_ru);
 mergesort(ARRAY, num, sizeof(int), cmp);
 gettimeofday(&end_wall, ((void *)0));
 getrusage(RUSAGE_SELF,&end_ru);
    diff_wall = tv_diff(start_wall, end_wall);
    diff_usr = tv_diff(start_ru.ru_utime, end_ru.ru_utime);
    diff_sys = tv_diff(start_ru.ru_stime, end_ru.ru_stime);
    printf("0 threads:  ");
    printf("%d.%06ds wall;  ", diff_wall.tv_sec, diff_wall.tv_usec);
    printf("%d.%06ds user;  ", diff_usr.tv_sec, diff_usr.tv_usec);
    printf("%d.%06ds sys\n", diff_sys.tv_sec, diff_sys.tv_usec);
 gettimeofday(&start_wall, ((void *)0));
 getrusage(RUSAGE_SELF, &start_ru);
 mt_mergesort(ARRAY_2, num, sizeof(int), cmp, 1);
 gettimeofday(&end_wall, ((void *)0));
 getrusage(RUSAGE_SELF,&end_ru);
    diff_wall = tv_diff(start_wall, end_wall);
    diff_usr = tv_diff(start_ru.ru_utime, end_ru.ru_utime);
    diff_sys = tv_diff(start_ru.ru_stime, end_ru.ru_stime);
    printf("1 threads:  ");
    printf("%d.%06ds wall;  ", diff_wall.tv_sec, diff_wall.tv_usec);
    printf("%d.%06ds user;  ", diff_usr.tv_sec, diff_usr.tv_usec);
    printf("%d.%06ds sys\n", diff_sys.tv_sec, diff_sys.tv_usec);
    gettimeofday(&start_wall, ((void *)0));
 getrusage(RUSAGE_SELF, &start_ru);
 mt_mergesort(ARRAY_3, num, sizeof(int), cmp, 2);
 gettimeofday(&end_wall, ((void *)0));
 getrusage(RUSAGE_SELF,&end_ru);
    diff_wall = tv_diff(start_wall, end_wall);
    diff_usr = tv_diff(start_ru.ru_utime, end_ru.ru_utime);
    diff_sys = tv_diff(start_ru.ru_stime, end_ru.ru_stime);
    printf("2 threads:  ");
    printf("%d.%06ds wall;  ", diff_wall.tv_sec, diff_wall.tv_usec);
    printf("%d.%06ds user;  ", diff_usr.tv_sec, diff_usr.tv_usec);
    printf("%d.%06ds sys\n", diff_sys.tv_sec, diff_sys.tv_usec);
    gettimeofday(&start_wall, ((void *)0));
 getrusage(RUSAGE_SELF, &start_ru);
 mt_mergesort(ARRAY_4, num, sizeof(int), cmp, 4);
 gettimeofday(&end_wall, ((void *)0));
 getrusage(RUSAGE_SELF,&end_ru);
    diff_wall = tv_diff(start_wall, end_wall);
    diff_usr = tv_diff(start_ru.ru_utime, end_ru.ru_utime);
    diff_sys = tv_diff(start_ru.ru_stime, end_ru.ru_stime);
    printf("4 threads:  ");
    printf("%d.%06ds wall;  ", diff_wall.tv_sec, diff_wall.tv_usec);
    printf("%d.%06ds user;  ", diff_usr.tv_sec, diff_usr.tv_usec);
    printf("%d.%06ds sys\n", diff_sys.tv_sec, diff_sys.tv_usec);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
ARRAY
int *

variable_types: i int

variable_types: k int

variable_types: num int

variable_types: seed int

variable_types: struct rusage { struct timeval { long tv_sec; long tv_usec; } ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; }

variable_types:
cmp
int (*)(void *, void *)

user_defined_types: struct rusage { struct timeval ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; }


merge

decompiled_code:
void __fastcall merge(char *a1, __int64 a2, __int64 a3, size_t a4, int (__fastcall *a5)(char *, char *))
{
__int64 v5; // r13
__int64 v6; // r12
char *v8; // r14
char *v9; // rbp
size_t v10; // rdx
char *v11; // r15
char *v12; // rsi
const void *v13; // rsi
char *dest; // [rsp+10h] [rbp-48h]
size_t n; // [rsp+18h] [rbp-40h]

v5 = a2;
v6 = a3;
n = a4 * (a2 + a3);
dest = (char *)malloc(n);
if ( !dest )
err(71, "error allocating workspace");
v8 = a1;
v9 = dest;
v10 = a4 * a2;
v11 = &a1[a4 * a2];
if ( !a2 || !v6 )
{
v8 = a1;
goto LABEL_10;
}
do
{
if ( a5(v8, v11) >= 0 )
{
v12 = v11;
v11 += a4;
--v6;
memcpy(v9, v12, a4);
v9 += a4;
if ( !v5 )
break;
continue;
}
v13 = v8;
--v5;
v8 += a4;
memcpy(v9, v13, a4);
v9 += a4;
if ( !v5 )
break;
}
while ( v6 );
v10 = a4 * v5;
LABEL_10:
memcpy(v9, v8, v10);
memcpy(v9, v11, v6 * a4);
memcpy(a1, dest, n);
free(dest);
}

canonical_decompiled_code:
void __fastcall func0(char *a1, __int64 a2, __int64 a3, size_t a4, int (__fastcall *a5)(char *, char *))
{
__int64 v5; // r13
__int64 v6; // r12
char *v8; // r14
char *v9; // rbp
size_t v10; // rdx
char *v11; // r15
char *v12; // rsi
const void *v13; // rsi
char *dest; // [rsp+10h] [rbp-48h]
size_t n; // [rsp+18h] [rbp-40h]

v5 = a2;
v6 = a3;
n = a4 * (a2 + a3);
dest = (char *)malloc(n);
if ( !dest )
err(71, "error allocating workspace");
v8 = a1;
v9 = dest;
v10 = a4 * a2;
v11 = &a1[a4 * a2];
if ( !a2 || !v6 )
{
v8 = a1;
goto LABEL_10;
}
do
{
if ( a5(v8, v11) >= 0 )
{
v12 = v11;
v11 += a4;
--v6;
memcpy(v9, v12, a4);
v9 += a4;
if ( !v5 )
break;
continue;
}
v13 = v8;
--v5;
v8 += a4;
memcpy(v9, v13, a4);
v9 += a4;
if ( !v5 )
break;
}
while ( v6 );
v10 = a4 * v5;
LABEL_10:
memcpy(v9, v8, v10);
memcpy(v9, v11, v6 * a4);
memcpy(a1, dest, n);
free(dest);
}

original_code:
static void merge(void *arr, size_t num_elem_a, size_t num_elem_b,
                  size_t elem_size, Compare_fn cmp)
{
    char *i_ptr, *j_ptr, *work_ptr;
    char *workspace;
    size_t total_elem = num_elem_a + num_elem_b;
    workspace = malloc(total_elem * elem_size);
    if (workspace == ((void *)0))
        err(71, "error allocating workspace");
    i_ptr = arr;
    j_ptr = i_ptr + elem_size * num_elem_a;
    work_ptr = workspace;
    while (num_elem_a && num_elem_b) {
        if (cmp(i_ptr, j_ptr) < 0) {
            memmove(work_ptr, i_ptr, elem_size);
            i_ptr += elem_size;
            num_elem_a--;
        }
        else {
            memmove(work_ptr, j_ptr, elem_size);
            j_ptr += elem_size;
            num_elem_b--;
        }
        work_ptr += elem_size;
    }
    memmove(work_ptr, i_ptr, elem_size * num_elem_a);
    memmove(work_ptr, j_ptr, elem_size * num_elem_b);
    memmove(arr, workspace, elem_size * total_elem);
    free(workspace);
}

canonical_original_code:
static void merge(void *arr, unsigned long num_elem_a, unsigned long num_elem_b, unsigned long elem_size, int (*cmp)(void *, void *))
{
    char *i_ptr; char *j_ptr; char *work_ptr;
    char *workspace;
    unsigned long total_elem = num_elem_a + num_elem_b;
    workspace = malloc(total_elem * elem_size);
    if (workspace == ((void *)0))
        err(71, "error allocating workspace");
    i_ptr = arr;
    j_ptr = i_ptr + elem_size * num_elem_a;
    work_ptr = workspace;
    while (num_elem_a && num_elem_b) {
        if (cmp(i_ptr, j_ptr) < 0) {
            memmove(work_ptr, i_ptr, elem_size);
            i_ptr += elem_size;
            num_elem_a--;
        }
        else {
            memmove(work_ptr, j_ptr, elem_size);
            j_ptr += elem_size;
            num_elem_b--;
        }
        work_ptr += elem_size;
    }
    memmove(work_ptr, i_ptr, elem_size * num_elem_a);
    memmove(work_ptr, j_ptr, elem_size * num_elem_b);
    memmove(arr, workspace, elem_size * total_elem);
    free(workspace);
}

variable_types:
arr
void *

variable_types:
workspace
char *


mergesort

decompiled_code:
void __fastcall mergesort(char *a1, unsigned __int64 a2, size_t a3, int (__fastcall *a4)(char *, char *))
{
__int64 v6; // r12

if ( a2 > 1 && a4 != 0LL )
{
if ( a1 )
{
v6 = a2 - (a2 >> 1);
mergesort(a1, a2 >> 1, a3);
mergesort(&a1[a3 * (a2 >> 1)], v6, a3);
merge(a1, a2 >> 1, v6, a3, a4);
}
}
}

original_code:
void mergesort(void *arr, size_t num_elem, size_t elem_size, Compare_fn cmp) {
    size_t first_half_count, second_half_count;
    char *second_half_arr = arr;
    if (arr == ((void *)0) || cmp == ((void *)0) || num_elem <= 1)
        return;
    first_half_count = num_elem / 2;
    second_half_count = num_elem - first_half_count;
    second_half_arr += first_half_count * elem_size;
    mergesort(arr, first_half_count, elem_size, cmp);
    mergesort(second_half_arr, second_half_count, elem_size, cmp);
    merge(arr, first_half_count, second_half_count, elem_size, cmp);
}

canonical_original_code:
void mergesort(void *arr, unsigned long num_elem, unsigned long elem_size, int (*cmp)(void *, void *)) {
    unsigned long first_half_count; unsigned long second_half_count;
    char *second_half_arr = arr;
    if (arr == ((void *)0) || cmp == ((void *)0) || num_elem <= 1)
        return;
    first_half_count = num_elem / 2;
    second_half_count = num_elem - first_half_count;
    second_half_arr += first_half_count * elem_size;
    mergesort(arr, first_half_count, elem_size, cmp);
    mergesort(second_half_arr, second_half_count, elem_size, cmp);
    merge(arr, first_half_count, second_half_count, elem_size, cmp);
}


decompiled_code:
void __fastcall merge_th(void *a1)
{
mergesort(*(char **)a1, *((_QWORD *)a1 + 1), *((_QWORD *)a1 + 2), *((int (__fastcall **)(char *, char *))a1 + 3));
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
func1(*(char **)a1, *((_QWORD *)a1 + 1), *((_QWORD *)a1 + 2), *((int (__fastcall **)(char *, char *))a1 + 3));
}

original_code:
void *merge_th(void *merge_struct)
{
    Merge_mem *pars = (Merge_mem *) merge_struct;
    mergesort(pars->array, pars->num_elem, pars->elem_size, pars->cmp_f);
    return;
}

canonical_original_code:
void *merge_th(void *merge_struct)
{
    struct Merge_mem *pars = (Merge_mem *) merge_struct;
    mergesort(pars->array, pars->num_elem, pars->elem_size, pars->cmp_f);
    return;
}

variable_types: struct Merge_mem { void *array; unsigned long num_elem; unsigned long elem_size; int (*cmp_f)(void *, void *); } *