repo: AlexPnt/Library-Management-System

decompiled_code:
__int64 __fastcall compara_data(unsigned __int64 a1, int a2, unsigned __int64 a3, int a4)
{
int v4; // er9
unsigned __int64 v5; // rdi
int v6; // er8
unsigned __int64 v7; // rdx
__int64 result; // rax

v4 = a1;
v5 = HIDWORD(a1);
v6 = a3;
v7 = HIDWORD(a3);
result = 0xFFFFFFFFLL;
if ( a2 >= a4 )
{
result = 1LL;
if ( a2 <= a4 )
{
result = 0xFFFFFFFFLL;
if ( (int)v5 >= (int)v7 )
{
result = 1LL;
if ( (int)v5 <= (int)v7 )
{
result = 0xFFFFFFFFLL;
if ( v4 >= v6 )
result = v4 > v6;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1, int a2, unsigned __int64 a3, int a4)
{
int v4; // er9
unsigned __int64 v5; // rdi
int v6; // er8
unsigned __int64 v7; // rdx
__int64 result; // rax

v4 = a1;
v5 = HIDWORD(a1);
v6 = a3;
v7 = HIDWORD(a3);
result = 0xFFFFFFFFLL;
if ( a2 >= a4 )
{
result = 1LL;
if ( a2 <= a4 )
{
result = 0xFFFFFFFFLL;
if ( (int)v5 >= (int)v7 )
{
result = 1LL;
if ( (int)v5 <= (int)v7 )
{
result = 0xFFFFFFFFLL;
if ( v4 >= v6 )
result = v4 > v6;
}
}
}
}
return result;
}

original_code:
int compara_data(Data d1,Data d2)
{
    int comparacao;
    if(d1.ano<d2.ano)
        comparacao= -1;
    else if(d1.ano>d2.ano)
        comparacao= 1;
    else
    {
        if(d1.mes<d2.mes)
            comparacao= -1;
        else if(d1.mes>d2.mes)
            comparacao= 1;
        else
        {
            if(d1.dia<d2.dia)
                comparacao= -1;
            else if(d1.dia>d2.dia)
                comparacao= 1;
            else
                comparacao= 0;
        }
    }
    return comparacao;
}

canonical_original_code:
int compara_data(struct Data d1, struct Data d2)
{
    int comparacao;
    if(d1.ano<d2.ano)
        comparacao= -1;
    else if(d1.ano>d2.ano)
        comparacao= 1;
    else
    {
        if(d1.mes<d2.mes)
            comparacao= -1;
        else if(d1.mes>d2.mes)
            comparacao= 1;
        else
        {
            if(d1.dia<d2.dia)
                comparacao= -1;
            else if(d1.dia>d2.dia)
                comparacao= 1;
            else
                comparacao= 0;
        }
    }
    return comparacao;
}

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

variable_types: comparacao int


decompiled_code:
__int64 __fastcall sete_dias(unsigned __int64 a1, int a2)
{
struct tm *v2; // rax
time_t timer; // [rsp+28h] [rbp-10h] BYREF

timer = time(0LL) - 604800;
v2 = localtime(&timer);
return compara_data(*(_QWORD *)&v2->tm_mday + 0x100000000LL, v2->tm_year + 1900, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1, int a2)
{
struct tm *v2; // rax
time_t timer; // [rsp+28h] [rbp-10h] BYREF

timer = time(0LL) - 604800;
v2 = localtime(&timer);
return func0(*(_QWORD *)&v2->tm_mday + 0x100000000LL, v2->tm_year + 1900, a1, a2);
}

original_code:
int sete_dias(Data data)
{
    struct tm *data_aux;
    time_t data_hj,data_7dias;
    Data data_comp;
    data_hj = time(0);
    data_7dias = data_hj - (7*24*3600);
    data_aux = localtime(&data_7dias);
    data_comp.ano = data_aux->tm_year+1900;
    data_comp.mes = data_aux->tm_mon+1;
    data_comp.dia = data_aux->tm_mday;
    return (compara_data(data_comp,data));
}

canonical_original_code:
int sete_dias(struct Data data)
{
    struct tm *data_aux;
    long data_hj; long data_7dias;
    struct Data data_comp;
    data_hj = time(0);
    data_7dias = data_hj - (7*24*3600);
    data_aux = localtime(&data_7dias);
    data_comp.ano = data_aux->tm_year+1900;
    data_comp.mes = data_aux->tm_mon+1;
    data_comp.dia = data_aux->tm_mday;
    return (compara_data(data_comp,data));
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

return_type: int

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


decompiled_code:
__int64 __fastcall data_actual(_DWORD *a1)
{
struct tm *v1; // rax
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
a1[2] = v1->tm_year + 1900;
a1[1] = v1->tm_mon + 1;
result = (unsigned int)v1->tm_mday;
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1)
{
struct tm *v1; // rax
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v1 = localtime(&timer);
a1[2] = v1->tm_year + 1900;
a1[1] = v1->tm_mon + 1;
result = (unsigned int)v1->tm_mday;
*a1 = result;
return result;
}

original_code:
void data_actual(Data *d1)
{
    struct tm *ptr_data;
    time_t lt;
    lt = time(0);
    ptr_data=localtime(&lt);
    d1->ano = ptr_data->tm_year+1900;
    d1->mes = ptr_data->tm_mon+1;
    d1->dia = ptr_data->tm_mday;
}

canonical_original_code:
void data_actual(struct Data *d1)
{
    struct tm *ptr_data;
    long lt;
    lt = time(0);
    ptr_data=localtime(&lt);
    d1->ano = ptr_data->tm_year+1900;
    d1->mes = ptr_data->tm_mon+1;
    d1->dia = ptr_data->tm_mday;
}

variable_types: struct Data { int dia; int mes; int ano; } *

variable_types: lt long

return_type: void

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


decompiled_code:
const char *__fastcall valida_u(__int64 a1)
{
const char *v1; // rax
const char *v2; // rbx
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

do
{
do
{
printf("\nIntroduza o codigo do utente: ");
_isoc99_scanf("%d", v4);
puts("\n");
}
while ( getchar() != 10 );
}
while ( v4[0] <= 0 );
v1 = (const char *)pesquisa_lista_u(a1);
v2 = v1;
if ( v1 )
printf("\tNome: %s\n\n", v1);
return v2;
}

canonical_decompiled_code:
const char *__fastcall func3(__int64 a1)
{
const char *v1; // rax
const char *v2; // rbx
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

do
{
do
{
printf("\nIntroduza o codigo do utente: ");
_isoc99_scanf("%d", v4);
puts("\n");
}
while ( getchar() != 10 );
}
while ( v4[0] <= 0 );
v1 = (const char *)pesquisa_lista_u(a1);
v2 = v1;
if ( v1 )
printf("\tNome: %s\n\n", v1);
return v2;
}

original_code:
Utente valida_u(Utente utentes)
{
    int utente_code;
    Utente aux_u;
    do {
    printf("\nIntroduza o codigo do utente: ");
    scanf("%d",&utente_code);
    printf("\n\n");
    } while (getchar()!='\n' || utente_code<1);
    if((aux_u=pesquisa_lista_u(utentes,utente_code)))
        printf("\tNome: %s\n\n",aux_u->registo.nome);
    return aux_u;
}

canonical_original_code:
struct no_u *valida_u(struct no_u *utentes)
{
    int utente_code;
    struct no_u *aux_u;
    do {
    printf("\nIntroduza o codigo do utente: ");
    scanf("%d",&utente_code);
    printf("\n\n");
    } while (getchar()!='\n' || utente_code<1);
    if((aux_u=pesquisa_lista_u(utentes,utente_code)))
        printf("\tNome: %s\n\n",aux_u->registo.nome);
    return aux_u;
}

variable_types:
utentes
struct no_u *

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:
const char *__fastcall valida_l(__int64 a1)
{
const char *v1; // rax
const char *v2; // rbx
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

do
{
do
{
printf("\nIntroduza o codigo do livro: ");
_isoc99_scanf("%d", v4);
puts("\n");
}
while ( getchar() != 10 );
}
while ( v4[0] <= 0 );
v1 = (const char *)pesquisa_lista_l(a1);
v2 = v1;
if ( v1 )
printf("\tTitulo: %s\n\n", v1);
return v2;
}

canonical_decompiled_code:
const char *__fastcall func4(__int64 a1)
{
const char *v1; // rax
const char *v2; // rbx
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

do
{
do
{
printf("\nIntroduza o codigo do livro: ");
_isoc99_scanf("%d", v4);
puts("\n");
}
while ( getchar() != 10 );
}
while ( v4[0] <= 0 );
v1 = (const char *)pesquisa_lista_l(a1);
v2 = v1;
if ( v1 )
printf("\tTitulo: %s\n\n", v1);
return v2;
}

original_code:
Livro valida_l(Livro livros)
{
    int livro_code;
    Livro aux_l;
    do {
    printf("\nIntroduza o codigo do livro: ");
    scanf("%d",&livro_code);
    printf("\n\n");
    } while (getchar()!='\n' || livro_code<1);
    if((aux_l=pesquisa_lista_l(livros,livro_code)))
        printf("\tTitulo: %s\n\n",aux_l->dados.nome);
    return aux_l;
}

canonical_original_code:
struct no_l *valida_l(struct no_l *livros)
{
    int livro_code;
    struct no_l *aux_l;
    do {
    printf("\nIntroduza o codigo do livro: ");
    scanf("%d",&livro_code);
    printf("\n\n");
    } while (getchar()!='\n' || livro_code<1);
    if((aux_l=pesquisa_lista_l(livros,livro_code)))
        printf("\tTitulo: %s\n\n",aux_l->dados.nome);
    return aux_l;
}

variable_types:
livros
struct no_l *

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

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


decompiled_code:
__int64 __fastcall valida_r(__int64 a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

do
{
do
{
printf("\nIntroduza o codigo do livro: ");
_isoc99_scanf("%d", v2);
puts("\n");
}
while ( getchar() != 10 );
}
while ( v2[0] <= 0 );
return pesquisa_lista_r(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

do
{
do
{
printf("\nIntroduza o codigo do livro: ");
_isoc99_scanf("%d", v2);
puts("\n");
}
while ( getchar() != 10 );
}
while ( v2[0] <= 0 );
return pesquisa_lista_r(a1);
}

original_code:
Requisit valida_r(Requisit requisit)
{
    int livro_code;
    do {
    printf("\nIntroduza o codigo do livro: ");
    scanf("%d",&livro_code);
    printf("\n\n");
    } while (getchar()!='\n' || livro_code<1);
    return (pesquisa_lista_r(requisit,livro_code));
}

canonical_original_code:
struct no_r *valida_r(struct no_r *requisit)
{
    int livro_code;
    do {
    printf("\nIntroduza o codigo do livro: ");
    scanf("%d",&livro_code);
    printf("\n\n");
    } while (getchar()!='\n' || livro_code<1);
    return (pesquisa_lista_r(requisit,livro_code));
}

variable_types:
requisit
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; } *

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; }


original_code:
int vagas_u(Requisit requisit, int utente_code)
{
    int conta=0;
    Requisit aux_r;
    f_espera aux_fila;
    aux_r = requisit->prox;
    while(aux_r)
    {
        if(aux_r->info.cod_utente==utente_code)
            conta++;
        aux_fila = aux_r->info.reserva.primeiro;
        while(aux_fila)
        {
            if(aux_fila->cod_utente==utente_code)
                conta++;
            aux_fila = aux_fila->prox;
        }
        aux_r=aux_r->prox;
    }
    if(conta<4)
        return 1;
    else return 0;
}

canonical_original_code:
int vagas_u(struct no_r *requisit, int utente_code)
{
    int conta = 0;
    struct no_r *aux_r;
    struct node_fila *aux_fila;
    aux_r = requisit->prox;
    while(aux_r)
    {
        if(aux_r->info.cod_utente==utente_code)
            conta++;
        aux_fila = aux_r->info.reserva.primeiro;
        while(aux_fila)
        {
            if(aux_fila->cod_utente==utente_code)
                conta++;
            aux_fila = aux_fila->prox;
        }
        aux_r=aux_r->prox;
    }
    if(conta<4)
        return 1;
    else return 0;
}

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; } *

variable_types: conta int


clear

decompiled_code:
int clear()
{
return system("clear");
}

canonical_decompiled_code:
int func7()
{
return system("clear");
}

original_code:
void clear()
{
    system("clear");
}

canonical_original_code:
void clear()
{
    system("clear");
}


decompiled_code:
int __fastcall imprime_info_l(const char *a1, __int64 a2)
{
__int64 v2; // rbp
unsigned int *i; // rbx

if ( !a1 )
return puts("\n\tO livro com esse codigo nao existe.\n\n");
v2 = pesquisa_lista_r(a2);
if ( !v2 )
return printf("\tTitulo: %s\n\n\tO livro nao se encontra requisitado.\n\n\n", a1);
clear();
printf("\n\n\n\tInformacao sobre o livro com o titulo: ' %s '\n\n", a1);
puts("+--------------------------------------------------------------+");
puts("| Codigo do utente | Data de | Codigo dos utentes em espera |");
puts("| que o requisitou | Requisicao | com pedido de reserva |");
puts("+--------------------------------------------------------------+");
printf(
"%12d %02d/%02d/%-8d\n\n",
*(unsigned int *)(v2 + 4),
*(unsigned int *)(v2 + 8),
*(unsigned int *)(v2 + 12),
*(unsigned int *)(v2 + 16));
for ( i = *(unsigned int **)(v2 + 24); i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf("%50d \n\n", *i);
return puts("+--------------------------------------------------------------+\n\n");
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, __int64 a2)
{
__int64 v2; // rbp
unsigned int *i; // rbx

if ( !a1 )
return puts("\n\tO livro com esse codigo nao existe.\n\n");
v2 = pesquisa_lista_r(a2);
if ( !v2 )
return printf("\tTitulo: %s\n\n\tO livro nao se encontra requisitado.\n\n\n", a1);
func7();
printf("\n\n\n\tInformacao sobre o livro com o titulo: ' %s '\n\n", a1);
puts("+--------------------------------------------------------------+");
puts("| Codigo do utente | Data de | Codigo dos utentes em espera |");
puts("| que o requisitou | Requisicao | com pedido de reserva |");
puts("+--------------------------------------------------------------+");
printf(
"%12d %02d/%02d/%-8d\n\n",
*(unsigned int *)(v2 + 4),
*(unsigned int *)(v2 + 8),
*(unsigned int *)(v2 + 12),
*(unsigned int *)(v2 + 16));
for ( i = *(unsigned int **)(v2 + 24); i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf("%50d \n\n", *i);
return puts("+--------------------------------------------------------------+\n\n");
}

original_code:
void imprime_info_l(Livro aux_l,Requisit requisit)
{
    Requisit aux_r;
    f_espera aux_fila;
    if(aux_l)
    {
        aux_r = pesquisa_lista_r(requisit,aux_l->dados.cod_livro);
        if(aux_r)
        {
            clear();
            printf("\n\n\n\tInformacao sobre o livro com o titulo: ' %s '\n\n",aux_l->dados.nome);
            printf("+--------------------------------------------------------------+\n");
            printf("| Codigo do utente |  Data de   | Codigo dos utentes em espera |\n");
            printf("| que o requisitou | Requisicao |   com pedido de reserva      |\n");
            printf("+--------------------------------------------------------------+\n");
            printf("%12d         %02d/%02d/%-8d\n\n",aux_r->info.cod_utente,aux_r->info.data_r.dia,aux_r->info.data_r.mes,aux_r->info.data_r.ano);
            aux_fila = aux_r->info.reserva.primeiro;
            while(aux_fila)
            {
                printf("%50d \n\n",aux_fila->cod_utente);
                aux_fila = aux_fila->prox;
            }
        printf("+--------------------------------------------------------------+\n\n\n");
        }
        else printf("\tTitulo: %s\n\n\tO livro nao se encontra requisitado.\n\n\n",aux_l->dados.nome);
    }
    else
        printf("\n\tO livro com esse codigo nao existe.\n\n\n");
}

canonical_original_code:
void imprime_info_l(struct no_l *aux_l, struct no_r *requisit)
{
    struct no_r *aux_r;
    struct node_fila *aux_fila;
    if(aux_l)
    {
        aux_r = pesquisa_lista_r(requisit,aux_l->dados.cod_livro);
        if(aux_r)
        {
            clear();
            printf("\n\n\n\tInformacao sobre o livro com o titulo: ' %s '\n\n",aux_l->dados.nome);
            printf("+--------------------------------------------------------------+\n");
            printf("| Codigo do utente |  Data de   | Codigo dos utentes em espera |\n");
            printf("| que o requisitou | Requisicao |   com pedido de reserva      |\n");
            printf("+--------------------------------------------------------------+\n");
            printf("%12d         %02d/%02d/%-8d\n\n",aux_r->info.cod_utente,aux_r->info.data_r.dia,aux_r->info.data_r.mes,aux_r->info.data_r.ano);
            aux_fila = aux_r->info.reserva.primeiro;
            while(aux_fila)
            {
                printf("%50d \n\n",aux_fila->cod_utente);
                aux_fila = aux_fila->prox;
            }
        printf("+--------------------------------------------------------------+\n\n\n");
        }
        else printf("\tTitulo: %s\n\n\tO livro nao se encontra requisitado.\n\n\n",aux_l->dados.nome);
    }
    else
        printf("\n\tO livro com esse codigo nao existe.\n\n\n");
}

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

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


pause

decompiled_code:
int pause()
{
return system("read -p 'Prima qualquer tecla para continuar . . .'");
}

canonical_decompiled_code:
int func9()
{
return system("read -p 'Prima qualquer tecla para continuar . . .'");
}

original_code:
void pause()
{
    system("read -p 'Prima qualquer tecla para continuar . . .'");
}


original_code:
int historial_u(Requisit requisit,Livro livros,int utente_code,int opcao)
{
    Livro aux_l;
    Requisit aux_r;
    f_espera aux_fila;
    int existe=0,conta=0;
    aux_r = requisit->prox;
    if (opcao==1)
        printf("\n\n\tLista de livros requisitados pelo utente:\n\n");
    else if (opcao==2)
        printf("\n\n\tLista de livros reservados pelo utente:\n\n");
     else if (opcao==3)
        printf("\n\n\n\tLista de livros requisitados e reservados pelo utente:\n\n");
    printf("+--------------------------------------------------------------------------------------------+\n");
    printf("| Cod. Livro |                        Nome do Livro                          |      OBS      |\n");
    printf("+--------------------------------------------------------------------------------------------+\n");
    while(aux_r)
    {
        if (opcao==1 || opcao==3)
        {
            if(aux_r->info.cod_utente==utente_code)
            {
                aux_l = pesquisa_lista_l(livros,aux_r->info.cod_livro);
                printf("%9d       %-60s    requisitado\n\n",aux_r->info.cod_livro,aux_l->dados.nome);
                existe=1;
                conta++;
            }
        }
        if (opcao==2 || opcao==3)
        {
            aux_fila = aux_r->info.reserva.primeiro;
            while(aux_fila)
            {
                if(aux_fila->cod_utente==utente_code)
                {
                    aux_l = pesquisa_lista_l(livros,aux_r->info.cod_livro);
                    printf("%9d       %-60s    (reservado)\n\n",aux_l->dados.cod_livro,aux_l->dados.nome);
                    existe=1;
                    conta++;
                }
                aux_fila = aux_fila->prox;
            }
        }
        aux_r=aux_r->prox;
        if(conta==20)
        {
            conta=0;
            pause();
        }
    }
    printf("+--------------------------------------------------------------------------------------------+\n\n\n");
    return existe;
}

canonical_original_code:
int historial_u(struct no_r *requisit, struct no_l *livros, int utente_code, int opcao)
{
    struct no_l *aux_l;
    struct no_r *aux_r;
    struct node_fila *aux_fila;
    int existe = 0; int conta = 0;
    aux_r = requisit->prox;
    if (opcao==1)
        printf("\n\n\tLista de livros requisitados pelo utente:\n\n");
    else if (opcao==2)
        printf("\n\n\tLista de livros reservados pelo utente:\n\n");
     else if (opcao==3)
        printf("\n\n\n\tLista de livros requisitados e reservados pelo utente:\n\n");
    printf("+--------------------------------------------------------------------------------------------+\n");
    printf("| Cod. Livro |                        Nome do Livro                          |      OBS      |\n");
    printf("+--------------------------------------------------------------------------------------------+\n");
    while(aux_r)
    {
        if (opcao==1 || opcao==3)
        {
            if(aux_r->info.cod_utente==utente_code)
            {
                aux_l = pesquisa_lista_l(livros,aux_r->info.cod_livro);
                printf("%9d       %-60s    requisitado\n\n",aux_r->info.cod_livro,aux_l->dados.nome);
                existe=1;
                conta++;
            }
        }
        if (opcao==2 || opcao==3)
        {
            aux_fila = aux_r->info.reserva.primeiro;
            while(aux_fila)
            {
                if(aux_fila->cod_utente==utente_code)
                {
                    aux_l = pesquisa_lista_l(livros,aux_r->info.cod_livro);
                    printf("%9d       %-60s    (reservado)\n\n",aux_l->dados.cod_livro,aux_l->dados.nome);
                    existe=1;
                    conta++;
                }
                aux_fila = aux_fila->prox;
            }
        }
        aux_r=aux_r->prox;
        if(conta==20)
        {
            conta=0;
            pause();
        }
    }
    printf("+--------------------------------------------------------------------------------------------+\n\n\n");
    return existe;
}

variable_types: opcao int

variable_types: existe int

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


boneco

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

if ( a1 == 1 )
result = system("cat entrada.txt");
else
result = system("cat saida.txt");
return result;
}

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

if ( a1 == 1 )
result = system("cat entrada.txt");
else
result = system("cat saida.txt");
return result;
}

original_code:
void boneco(int tipo)
{
    if(tipo==1)
    {
        system("cat entrada.txt");
    }
    else
    {
        system("cat saida.txt");
    }
}

variable_types: tipo int


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

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

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

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

original_code:
Livro cria_lista_l(void)
{
    Livro aux;
    aux = (Livro) malloc (sizeof (No_livros));
    if (aux != ((void *)0)) {
        strcpy(aux->dados.nome,"0");
        aux->dados.cod_livro = 0;
        aux->prox = ((void *)0);
    }
    return aux;
}

canonical_original_code:
struct no_l *cria_lista_l()
{
    struct no_l *aux;
    aux = (struct no_l *) malloc (sizeof (No_livros));
    if (aux != ((void *)0)) {
        strcpy(aux->dados.nome,"0");
        aux->dados.cod_livro = 0;
        aux->prox = ((void *)0);
    }
    return aux;
}

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


decompiled_code:
_BOOL8 __fastcall lista_vazia_l(__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_l(Livro lista)
{
    return (lista->prox == ((void *)0) ? 1 : 0);
}

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


decompiled_code:
__int64 __fastcall destroi_lista_l(void *ptr)
{
void *v2; // rbp

while ( !lista_vazia_l((__int64)ptr) )
{
v2 = (void *)*((_QWORD *)ptr + 13);
free(ptr);
ptr = v2;
}
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
void *v2; // rbp

while ( !func1((__int64)ptr) )
{
v2 = (void *)*((_QWORD *)ptr + 13);
free(ptr);
ptr = v2;
}
free(ptr);
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 *


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;
}


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

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

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

*a3 = a1;
result = *(_QWORD *)(a1 + 104);
*a4 = result;
if ( result )
{
while ( 1 )
{
v7 = *(_DWORD *)(result + 100);
if ( v7 >= a2 )
break;
*a3 = result;
result = *(_QWORD *)(result + 104);
*a4 = result;
if ( !result )
return result;
}
if ( v7 != 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 **


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, &v4, &v3);
return v3;
}

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, &v4, &v3);
return v3;
}

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);
}


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

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

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

result = malloc(0x30uLL);
if ( result )
{
*result = 0;
result[1] = 0;
result[2] = 0;
result[3] = 0;
result[4] = 0;
*((_QWORD *)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;
}


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);
}


decompiled_code:
__int64 __fastcall destroi_lista_r(void *ptr)
{
void *v2; // rbp

while ( !lista_vazia_r((__int64)ptr) )
{
v2 = (void *)*((_QWORD *)ptr + 5);
free(ptr);
ptr = v2;
}
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
void *v2; // rbp

while ( !func1((__int64)ptr) )
{
v2 = (void *)*((_QWORD *)ptr + 5);
free(ptr);
ptr = v2;
}
free(ptr);
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 *


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, &v4, &v3);
return v3;
}

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
void *ptr; // [rsp+0h] [rbp-18h] BYREF
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

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

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

func4(a1, a2, &v4, &ptr);
v2 = ptr;
if ( ptr )
{
*(_QWORD *)(v4 + 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 )
{
*(_WORD *)result = 48;
result[25] = 0;
*((_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; } *


decompiled_code:
_BOOL8 __fastcall lista_vazia_u(__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(void *ptr)
{
void *v2; // rbp

while ( !lista_vazia_u((__int64)ptr) )
{
v2 = (void *)*((_QWORD *)ptr + 13);
free(ptr);
ptr = v2;
}
free(ptr);
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
int v7; // edx

*a3 = a1;
result = *(_QWORD *)(a1 + 104);
*a4 = result;
if ( result )
{
while ( 1 )
{
v7 = *(_DWORD *)(result + 100);
if ( v7 >= a2 )
break;
*a3 = result;
result = *(_QWORD *)(result + 104);
*a4 = result;
if ( !result )
return result;
}
if ( v7 != 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, &v4, &v3);
return v3;
}

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 v1; // ebp
unsigned int *v3; // r12

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

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int **a1)
{
unsigned int v1; // ebp
unsigned int *v3; // r12

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

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: code int


getConfStr

repo: AlexanderHaase/mprof

decompiled_code:
__int64 getConfStr()
{
if ( !confValue )
confValue = getenv(confKey);
return confValue;
}

canonical_decompiled_code:
__int64 func0()
{
if ( !confValue )
confValue = getenv(confKey);
return confValue;
}

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; // r12

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

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

v2 = s1;
v3 = strlen(s2);
if ( !*s1 )
return 0LL;
while ( strncmp(v2, s2, v3) )
{
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)
{
__int64 v4; // rbx
size_t v5; // rax

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

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

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

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; // rbx
__int64 v4; // r13
int v5; // eax

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v4; // r13
int v5; // eax

v2 = defaultVtable[3]();
if ( *((_BYTE *)reallocLogFD + _tls_get_addr(&externalCall_tlsind)) )
{
v4 = _tls_get_addr(&externalCall_tlsind);
*((_BYTE *)reallocLogFD + v4) = 0;
v5 = snprintf(&textBuf[v4 - 1047], 0x3E8uLL, "realloc\t%llX\t%llu\t%llx\n", a1, a2, v2);
write(logFD, &textBuf[v4 - 1047], v5);
*((_BYTE *)reallocLogFD + v4) = 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; // rbx
__int64 v4; // r13
int v5; // eax

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v4; // r13
int v5; // eax

v2 = defaultVtable[2]();
if ( *((_BYTE *)reallocLogFD + _tls_get_addr(&externalCall_tlsind)) )
{
v4 = _tls_get_addr(&externalCall_tlsind);
*((_BYTE *)reallocLogFD + v4) = 0;
v5 = snprintf(&textBuf[v4 - 1047], 0x3E8uLL, "calloc\t%llu\t%llu\t%llx\n", a1, a2, v2);
write(logFD, &textBuf[v4 - 1047], v5);
*((_BYTE *)reallocLogFD + v4) = 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
__int64 v2; // rbp
int v3; // eax

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

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

defaultVtable[1]();
result = _tls_get_addr(&externalCall_tlsind);
if ( *((_BYTE *)reallocLogFD + result) )
{
v2 = _tls_get_addr(&externalCall_tlsind);
*((_BYTE *)reallocLogFD + v2) = 0;
v3 = snprintf(&textBuf[v2 - 1047], 0x3E8uLL, "free\t%llX\n", a1);
result = write(logFD, &textBuf[v2 - 1047], v3);
*((_BYTE *)reallocLogFD + v2) = 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; // rbx
__int64 v3; // r12
int v4; // eax

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
__int64 v3; // r12
int v4; // eax

v1 = defaultVtable[0]();
if ( *((_BYTE *)reallocLogFD + _tls_get_addr(&externalCall_tlsind)) )
{
v3 = _tls_get_addr(&externalCall_tlsind);
*((_BYTE *)reallocLogFD + v3) = 0;
v4 = snprintf(&textBuf[v3 - 1047], 0x3E8uLL, "malloc\t%llu\t%llX\n", a1, v1);
write(logFD, &textBuf[v3 - 1047], v4);
*((_BYTE *)reallocLogFD + v3) = 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()
{
__int64 v0; // rax
__int64 v1; // rax
char *v2; // rbx
const char *v3; // rbp
__int64 result; // rax
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = getConfStr();
v1 = findArg(v0, "COUNTS_PATH", n);
v2 = "./mprof.counts";
if ( v1 )
{
v3 = (const char *)v1;
v2 = (char *)tmpAllocVtable[2](n[0] + 1, 1LL);
strncpy(v2, v3, n[0]);
}
mprofRecordInit();
sem_init(&mmapSem, 0, 1u);
if ( !(unsigned __int8)mmapOpen(&countsArea, v2, 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()
{
__int64 v0; // rax
__int64 v1; // rax
char *v2; // rbx
const char *v3; // rbp
__int64 result; // rax
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = getConfStr();
v1 = findArg(v0, "COUNTS_PATH", n);
v2 = "./mprof.counts";
if ( v1 )
{
v3 = (const char *)v1;
v2 = (char *)tmpAllocVtable[2](n[0] + 1, 1LL);
strncpy(v2, v3, n[0]);
}
mprofRecordInit();
sem_init(&mmapSem, 0, 1u);
if ( !(unsigned __int8)mmapOpen(&countsArea, v2, 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
_BYTE *v3; // r12
__int64 *v4; // rax

result = _tls_get_addr(&mprofLocalCounts_tlsind);
if ( !*(_QWORD *)result )
{
v1 = _InterlockedExchangeAdd64(threadID, 1uLL);
v2 = 8 * (5 * v1 + 5);
if ( qword_308 < v2 )
{
sem_wait(&mmapSem);
if ( qword_308 < 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 = (_BYTE *)(qword_310 + v2 - 40);
v4 = (__int64 *)_tls_get_addr(&mprofLocalCounts_tlsind);
*v4 = (__int64)v3;
*v3 = 5;
result = *v4;
*(_WORD *)(result + 2) = v1;
}
return result;
}

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

result = _tls_get_addr(&mprofLocalCounts_tlsind);
if ( !*(_QWORD *)result )
{
v1 = _InterlockedExchangeAdd64(threadID, 1uLL);
v2 = 8 * (5 * v1 + 5);
if ( qword_308 < v2 )
{
sem_wait(&mmapSem);
if ( qword_308 < 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 = (_BYTE *)(qword_310 + v2 - 40);
v4 = (__int64 *)_tls_get_addr(&mprofLocalCounts_tlsind);
*v4 = (__int64)v3;
*v3 = 5;
result = *v4;
*(_WORD *)(result + 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; // rax
__int64 v4; // rax
const char *v5; // rbp
char *v6; // rbx
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = getConfStr();
v1 = (const char *)findArg(v0, "LOG_QTY", n);
if ( v1 )
growthQty = (void *)strtol(v1, 0LL, 10);
v2 = getConfStr();
v3 = (const char *)findArg(v2, "CACHE_QTY", n);
if ( v3 )
cacheQty = strtol(v3, 0LL, 10);
v4 = getConfStr();
v5 = (const char *)findArg(v4, "LOG_PATH", n);
v6 = "./mprof.log";
if ( v5 )
{
v6 = (char *)tmpAllocVtable[2](n[0] + 1, 1LL);
strncpy(v6, v5, n[0]);
}
if ( !(unsigned __int8)mmapOpen(&area, v6, 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; // rax
__int64 v4; // rax
const char *v5; // rbp
char *v6; // rbx
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = getConfStr();
v1 = (const char *)findArg(v0, "LOG_QTY", n);
if ( v1 )
growthQty = (void *)strtol(v1, 0LL, 10);
v2 = getConfStr();
v3 = (const char *)findArg(v2, "CACHE_QTY", n);
if ( v3 )
cacheQty = strtol(v3, 0LL, 10);
v4 = getConfStr();
v5 = (const char *)findArg(v4, "LOG_PATH", n);
v6 = "./mprof.log";
if ( v5 )
{
v6 = (char *)tmpAllocVtable[2](n[0] + 1, 1LL);
strncpy(v6, v5, n[0]);
}
if ( !(unsigned __int8)mmapOpen(&area, v6, 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:
_QWORD *populateCache()
{
signed __int64 v0; // rbx
unsigned __int64 v1; // rbp
_QWORD *result; // rax

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

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

v0 = _InterlockedExchangeAdd64((volatile signed __int64 *)&areaIndex, cacheQty);
v1 = 40 * (cacheQty + v0);
if ( qword_4B8 < v1 )
{
sem_wait(&mmapSem);
if ( qword_4B8 < v1 && !(unsigned __int8)mmapSize(&area, v1 + 40LL * (_QWORD)growthQty, 0LL) )
_assert_fail(
"mmapSize( &area, requiredSize + growthQty * sizeof( struct MprofRecordAlloc ), MMAP_AREA_SET )",
"src/mprofLogMmap.c",
0x32u,
"populateCache");
sem_post(&mmapSem);
}
*(_QWORD *)_tls_get_addr(&cache_tlsind) = qword_4C0 + 40 * v0;
result = (_QWORD *)_tls_get_addr(&cacheRemaining_tlsind);
*result = cacheQty;
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 v2; // rbp
_QWORD *v3; // r14
__int64 v4; // rax
__int64 *v5; // rbx
__int64 v6; // rax
__int64 v7; // r12

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
_QWORD *v3; // r14
__int64 v4; // rax
__int64 *v5; // rbx
__int64 v6; // rax
__int64 v7; // r12

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

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 v2; // rbp
_QWORD *v3; // r14
__int64 v4; // rax
__int64 *v5; // rbx
__int64 v6; // rax
__int64 v7; // r12

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
_QWORD *v3; // r14
__int64 v4; // rax
__int64 *v5; // rbx
__int64 v6; // rax
__int64 v7; // r12

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

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)
{
_QWORD *v1; // r12
__int64 v2; // rax
__int64 *v3; // rbx
__int64 v4; // rax
__int64 v5; // rbp

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
_QWORD *v1; // r12
__int64 v2; // rax
__int64 *v3; // rbx
__int64 v4; // rax
__int64 v5; // rbp

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

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 v1; // rbp
_QWORD *v2; // r13
__int64 v3; // rax
__int64 *v4; // rbx
__int64 v5; // rax
__int64 v6; // r12

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rbp
_QWORD *v2; // r13
__int64 v3; // rax
__int64 *v4; // rbx
__int64 v5; // rax
__int64 v6; // r12

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

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:
void *mprofLDInit()
{
__int64 v0; // rax
const char *v1; // rax
char *v2; // rbx
_QWORD *v3; // r12
const char **v4; // rbp
const char *v5; // rbx
void *v6; // rax
void *result; // rax
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

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

canonical_decompiled_code:
void *func0()
{
__int64 v0; // rax
const char *v1; // rax
char *v2; // rbx
_QWORD *v3; // r12
const char **v4; // rbp
const char *v5; // rbx
void *v6; // rax
void *result; // rax
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

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

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 v4; // rbp
__int64 result; // rax
size_t v6; // rdx
void *v7; // rdi
void *v8; // rax

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

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

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

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:
char *__fastcall mallocTmpAlloc(unsigned __int64 a1)
{
char *v1; // rdx
char *result; // rax

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

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

if ( (unsigned __int64)tmpRemaining < a1 )
{
perror("ERROR: libmprof: mprofLDInit.c: tmp allocator out of space!");
result = 0LL;
}
else
{
v1 = (char *)&tmpBuf + 4096LL - (_QWORD)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 *