// File: /workspace/github_cpp_makefile_star2_O3/grmauri[P]pmm/pmm.cpp
// Function: testar_alocacao()
void testar_alocacao()
{
    const int tamanho = 500;
    const int repeticoes = 1000;
    //---
    clock_t h;
    double tempo;
    //---
    int **matDinamica;
    int matEstatica[tamanho][tamanho];

    printf("\n>>> TESTE COM UMA MATRIZ %d x %d - %d REPETICOES\n\n", tamanho, tamanho, repeticoes);

    //---
    h = clock();
    for(int r = 0; r < repeticoes; r++)
    {
        matDinamica = (int**)malloc(sizeof(int*) * tamanho);
        for(int i = 0; i < tamanho; i++)
            matDinamica[i] = (int*)malloc(sizeof(int) * tamanho);
        for(int i = 0; i < tamanho; i++)
            free(matDinamica[i]);
        free(matDinamica);
    }
    h = clock() - h;
    tempo = (double)h/CLOCKS_PER_SEC;
    printf("Tempo para alocar e desalocar usando MALLOC.....: %.5f segundos\n", tempo);
    //---

    //---
    h = clock();
    for(int r = 0; r < repeticoes; r++)
    {
        matDinamica = new int*[tamanho];
        for(int i = 0; i < tamanho; i++)
            matDinamica[i] = new int[tamanho];
        for(int i = 0; i < tamanho; i++)
            delete[] matDinamica[i];
        delete[] matDinamica;
    }
    h = clock() - h;
    tempo = (double)h/CLOCKS_PER_SEC;
    printf("Tempo para alocar e desalocar usando NEW........: %.5f segundos\n", tempo);
    //---

    //---
    h = clock();
    for(int r = 0; r < repeticoes; r++)
    {
        for(int i = 0; i < tamanho; i++)
            for(int j = 0; j < tamanho; j++)
                matEstatica[i][j] = 0;
    }
    h = clock() - h;
    tempo = (double)h/CLOCKS_PER_SEC;
    printf("\nTempo para zerar a matriz estatica com FOR......: %.5f segundos\n", tempo);
    //---

    //---
    h = clock();
    for(int r = 0; r < repeticoes; r++)
        memset(&matEstatica, 0, sizeof(matEstatica));
    h = clock() - h;
    tempo = (double)h/CLOCKS_PER_SEC;
    printf("Tempo para zerar a matriz estatica com MEMSET...: %.5f segundos\n", tempo);
    //---
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
leaq 0xd58(%rip), %rdi       # 0x63dd
xorl %r15d, %r15d
movl $0x1f4, %esi            # imm = 0x1F4
movl $0x1f4, %edx            # imm = 0x1F4
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %eax, %eax
callq 0x2050
callq 0x20a0
movq %rax, %rbx
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x2150
movq %rax, %r14
xorl %r12d, %r12d
movl $0x7d0, %edi            # imm = 0x7D0
callq 0x2150
movq %rax, (%r14,%r12,8)
incq %r12
cmpq $0x1f4, %r12            # imm = 0x1F4
jne 0x56b6
xorl %r12d, %r12d
movq (%r14,%r12,8), %rdi
callq 0x2120
incq %r12
cmpq $0x1f4, %r12            # imm = 0x1F4
jne 0x56d3
movq %r14, %rdi
callq 0x2120
incl %r15d
cmpl $0x3e8, %r15d           # imm = 0x3E8
jne 0x56a6
callq 0x20a0
subq %rbx, %rax
cvtsi2sd %rax, %xmm0
divsd 0x927(%rip), %xmm0      # 0x6038
leaq 0xcf9(%rip), %rdi       # 0x6411
movb $0x1, %al
callq 0x2050
xorl %r15d, %r15d
callq 0x20a0
movq %rax, %rbx
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x2030
movq %rax, %r14
xorl %r12d, %r12d
movl $0x7d0, %edi            # imm = 0x7D0
callq 0x2030
movq %rax, (%r14,%r12,8)
incq %r12
cmpq $0x1f4, %r12            # imm = 0x1F4
jne 0x573a
xorl %r12d, %r12d
movq (%r14,%r12,8), %rdi
testq %rdi, %rdi
je 0x5765
callq 0x2140
incq %r12
cmpq $0x1f4, %r12            # imm = 0x1F4
jne 0x5757
movq %r14, %rdi
callq 0x2140
incl %r15d
cmpl $0x3e8, %r15d           # imm = 0x3E8
jne 0x572a
callq 0x20a0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x89b(%rip), %xmm0      # 0x6038
leaq 0xcae(%rip), %rdi       # 0x6452
movb $0x1, %al
callq 0x2050
callq 0x20a0
movq %rax, %rbx
callq 0x20a0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x86d(%rip), %xmm0      # 0x6038
leaq 0xcc1(%rip), %rdi       # 0x6493
movb $0x1, %al
callq 0x2050
callq 0x20a0
movq %rax, %rbx
callq 0x20a0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x83f(%rip), %xmm0      # 0x6038
leaq 0xcd5(%rip), %rdi       # 0x64d5
movb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x2050