// File: 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 %rbp
movq %rsp, %rbp
subq $0xf42a0, %rsp          # imm = 0xF42A0
movl $0x1f4, -0x4(%rbp)      # imm = 0x1F4
movl $0x3e8, -0x8(%rbp)      # imm = 0x3E8
leaq 0x1097(%rip), %rdi      # 0x7457
movl $0x1f4, %edx            # imm = 0x1F4
movl $0x3e8, %ecx            # imm = 0x3E8
movl %edx, %esi
movb $0x0, %al
callq 0x2050
callq 0x2100
movq %rax, -0x10(%rbp)
movl $0x0, -0xf4264(%rbp)
cmpl $0x3e8, -0xf4264(%rbp)  # imm = 0x3E8
jge 0x649f
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x2210
movq %rax, -0x20(%rbp)
movl $0x0, -0xf4268(%rbp)
cmpl $0x1f4, -0xf4268(%rbp)  # imm = 0x1F4
jge 0x6447
movl $0x7d0, %edi            # imm = 0x7D0
callq 0x2210
movq %rax, %rdx
movq -0x20(%rbp), %rax
movslq -0xf4268(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0xf4268(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4268(%rbp)
jmp 0x640e
movl $0x0, -0xf426c(%rbp)
cmpl $0x1f4, -0xf426c(%rbp)  # imm = 0x1F4
jge 0x6482
movq -0x20(%rbp), %rax
movslq -0xf426c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x21e0
movl -0xf426c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf426c(%rbp)
jmp 0x6451
movq -0x20(%rbp), %rdi
callq 0x21e0
movl -0xf4264(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4264(%rbp)
jmp 0x63e6
callq 0x2100
subq -0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
cvtsi2sdq -0x10(%rbp), %xmm0
movsd 0xb76(%rip), %xmm1      # 0x7030
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
leaq 0xfbc(%rip), %rdi       # 0x748b
movb $0x1, %al
callq 0x2050
callq 0x2100
movq %rax, -0x10(%rbp)
movl $0x0, -0xf4270(%rbp)
cmpl $0x3e8, -0xf4270(%rbp)  # imm = 0x3E8
jge 0x65ce
movl $0xfa0, %edi            # imm = 0xFA0
callq 0x2030
movq %rax, -0x20(%rbp)
movl $0x0, -0xf4274(%rbp)
cmpl $0x1f4, -0xf4274(%rbp)  # imm = 0x1F4
jge 0x654a
movl $0x7d0, %edi            # imm = 0x7D0
callq 0x2030
movq %rax, %rdx
movq -0x20(%rbp), %rax
movslq -0xf4274(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0xf4274(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4274(%rbp)
jmp 0x6511
movl $0x0, -0xf4278(%rbp)
cmpl $0x1f4, -0xf4278(%rbp)  # imm = 0x1F4
jge 0x659b
movq -0x20(%rbp), %rax
movslq -0xf4278(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xf4290(%rbp)
cmpq $0x0, %rax
je 0x6588
movq -0xf4290(%rbp), %rdi
callq 0x2200
jmp 0x658a
movl -0xf4278(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4278(%rbp)
jmp 0x6554
movq -0x20(%rbp), %rax
movq %rax, -0xf4298(%rbp)
cmpq $0x0, %rax
je 0x65b8
movq -0xf4298(%rbp), %rdi
callq 0x2200
jmp 0x65ba
movl -0xf4270(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4270(%rbp)
jmp 0x64e9
callq 0x2100
subq -0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
cvtsi2sdq -0x10(%rbp), %xmm0
movsd 0xa47(%rip), %xmm1      # 0x7030
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
leaq 0xece(%rip), %rdi       # 0x74cc
movb $0x1, %al
callq 0x2050
callq 0x2100
movq %rax, -0x10(%rbp)
movl $0x0, -0xf427c(%rbp)
cmpl $0x3e8, -0xf427c(%rbp)  # imm = 0x3E8
jge 0x66b4
movl $0x0, -0xf4280(%rbp)
cmpl $0x1f4, -0xf4280(%rbp)  # imm = 0x1F4
jge 0x669e
movl $0x0, -0xf4284(%rbp)
cmpl $0x1f4, -0xf4284(%rbp)  # imm = 0x1F4
jge 0x668b
movslq -0xf4280(%rbp), %rcx
leaq -0xf4260(%rbp), %rax
imulq $0x7d0, %rcx, %rcx      # imm = 0x7D0
addq %rcx, %rax
movslq -0xf4284(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0xf4284(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4284(%rbp)
jmp 0x6648
jmp 0x668d
movl -0xf4280(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4280(%rbp)
jmp 0x6632
jmp 0x66a0
movl -0xf427c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf427c(%rbp)
jmp 0x6618
callq 0x2100
subq -0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
cvtsi2sdq -0x10(%rbp), %xmm0
movsd 0x961(%rip), %xmm1      # 0x7030
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
leaq 0xe29(%rip), %rdi       # 0x750d
movb $0x1, %al
callq 0x2050
callq 0x2100
movq %rax, -0x10(%rbp)
movl $0x0, -0xf4288(%rbp)
cmpl $0x3e8, -0xf4288(%rbp)  # imm = 0x3E8
jge 0x672e
leaq -0xf4260(%rbp), %rdi
xorl %esi, %esi
movl $0xf4240, %edx          # imm = 0xF4240
callq 0x20d0
movl -0xf4288(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4288(%rbp)
jmp 0x66fe
callq 0x2100
subq -0x10(%rbp), %rax
movq %rax, -0x10(%rbp)
cvtsi2sdq -0x10(%rbp), %xmm0
movsd 0x8e7(%rip), %xmm1      # 0x7030
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
leaq 0xdf1(%rip), %rdi       # 0x754f
movb $0x1, %al
callq 0x2050
addq $0xf42a0, %rsp          # imm = 0xF42A0
popq %rbp
retq
nop