// File: /workspace/github_cpp_makefile_star2_O1/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 0xe0f(%rip), %rdi       # 0x63ad
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 0x55cf
xorl %r12d, %r12d
movq (%r14,%r12,8), %rdi
callq 0x2120
incq %r12
cmpq $0x1f4, %r12            # imm = 0x1F4
jne 0x55ec
movq %r14, %rdi
callq 0x2120
incl %r15d
cmpl $0x3e8, %r15d           # imm = 0x3E8
jne 0x55bf
callq 0x20a0
subq %rbx, %rax
cvtsi2sd %rax, %xmm0
divsd 0xa0e(%rip), %xmm0      # 0x6038
leaq 0xdb0(%rip), %rdi       # 0x63e1
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 0x5653
xorl %r12d, %r12d
movq (%r14,%r12,8), %rdi
testq %rdi, %rdi
je 0x567e
callq 0x2140
incq %r12
cmpq $0x1f4, %r12            # imm = 0x1F4
jne 0x5670
movq %r14, %rdi
callq 0x2140
incl %r15d
cmpl $0x3e8, %r15d           # imm = 0x3E8
jne 0x5643
callq 0x20a0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x982(%rip), %xmm0      # 0x6038
leaq 0xd65(%rip), %rdi       # 0x6422
movb $0x1, %al
callq 0x2050
callq 0x20a0
movq %rax, %rbx
callq 0x20a0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x954(%rip), %xmm0      # 0x6038
leaq 0xd78(%rip), %rdi       # 0x6463
movb $0x1, %al
callq 0x2050
callq 0x20a0
movq %rax, %rbx
callq 0x20a0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x926(%rip), %xmm0      # 0x6038
leaq 0xd8c(%rip), %rdi       # 0x64a5
movb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x2050
nop