// File: /workspace/github_cpp_makefile_star2_O2/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 0x947(%rip), %rdi       # 0x53ad
xorl %r15d, %r15d
movl $0x1f4, %esi            # imm = 0x1F4
movl $0x1f4, %edx            # imm = 0x1F4
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %eax, %eax
callq 0x2050
callq 0x20b0
movq %rax, %rbx
cmpl $0x3e8, %r15d           # imm = 0x3E8
je 0x4ae3
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x2150
movq %rax, %r14
xorl %r12d, %r12d
cmpq $0x1f4, %r12            # imm = 0x1F4
je 0x4abc
movl $0x7d0, %edi            # imm = 0x7D0
callq 0x2150
movq %rax, (%r14,%r12,8)
incq %r12
jmp 0x4aa0
xorl %r12d, %r12d
cmpq $0x1f4, %r12            # imm = 0x1F4
je 0x4ad6
movq (%r14,%r12,8), %rdi
callq 0x2120
incq %r12
jmp 0x4abf
movq %r14, %rdi
callq 0x2120
incl %r15d
jmp 0x4a87
callq 0x20b0
subq %rbx, %rax
cvtsi2sd %rax, %xmm0
divsd 0x540(%rip), %xmm0      # 0x5038
leaq 0x8e2(%rip), %rdi       # 0x53e1
movb $0x1, %al
callq 0x2050
xorl %r15d, %r15d
callq 0x20b0
movq %rax, %rbx
cmpl $0x3e8, %r15d           # imm = 0x3E8
je 0x4b72
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x2030
movq %rax, %r14
xorl %r12d, %r12d
cmpq $0x1f4, %r12            # imm = 0x1F4
je 0x4b46
movl $0x7d0, %edi            # imm = 0x7D0
callq 0x2030
movq %rax, (%r14,%r12,8)
incq %r12
jmp 0x4b2a
xorl %r12d, %r12d
cmpq $0x1f4, %r12            # imm = 0x1F4
je 0x4b65
movq (%r14,%r12,8), %rdi
testq %rdi, %rdi
je 0x4b60
callq 0x2140
incq %r12
jmp 0x4b49
movq %r14, %rdi
callq 0x2140
incl %r15d
jmp 0x4b11
callq 0x20b0
subq %rbx, %rax
cvtsi2sd %rax, %xmm0
divsd 0x4b1(%rip), %xmm0      # 0x5038
leaq 0x894(%rip), %rdi       # 0x5422
movb $0x1, %al
callq 0x2050
callq 0x20b0
movq %rax, %rbx
callq 0x20b0
subq %rbx, %rax
cvtsi2sd %rax, %xmm0
divsd 0x486(%rip), %xmm0      # 0x5038
leaq 0x8aa(%rip), %rdi       # 0x5463
movb $0x1, %al
callq 0x2050
callq 0x20b0
movq %rax, %rbx
callq 0x20b0
subq %rbx, %rax
cvtsi2sd %rax, %xmm0
divsd 0x45b(%rip), %xmm0      # 0x5038
leaq 0x8c1(%rip), %rdi       # 0x54a5
movb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x2050