// File: eliebe-5[P]Catmull-clark-subdivision/main.cc
// Function: main
int main(int argc, char * argv[])
{
    if(argc < 3)
        printf("ERROR: Not enough arguments.\n");
    else
    {
        Mesh m;

        m.generateHalfEdge(argv[1]);

        int count = atoi(argv[2]);

        auto s1 = std::chrono::high_resolution_clock::now();
        for(int i = 0; i < count; i++)
        {
            auto t1 = std::chrono::high_resolution_clock::now();
            m.subdivide();
            auto t2 = std::chrono::high_resolution_clock::now();
            double duration = (double)std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count() * 0.000000001;
            printf("Subdiv number %d took: %f seconds\n", i + 1, duration);
        }
        auto s2 = std::chrono::high_resolution_clock::now();
        double duration = (double)std::chrono::duration_cast<std::chrono::nanoseconds>(s2 - s1).count() * 0.000000001;
        printf("All subdivs took: %f seconds\n", duration);
        
    }
    return 0;
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movl $0x0, 0x124(%rsp)
movl %edi, 0x120(%rsp)
movq %rsi, 0x118(%rsp)
cmpl $0x3, 0x120(%rsp)
jge 0x246e
leaq 0x9bae(%rip), %rdi      # 0xc010
movb $0x0, %al
callq 0x2050
jmp 0x2662
leaq 0xa8(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x27f0
movq 0x38(%rsp), %rdi
movq 0x118(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0x28e0
jmp 0x2498
movq 0x118(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x2240
movl %eax, 0x98(%rsp)
callq 0x2060
movq %rax, 0x90(%rsp)
movl $0x0, 0x8c(%rsp)
movl 0x8c(%rsp), %eax
cmpl 0x98(%rsp), %eax
jge 0x25ca
callq 0x2060
movq %rax, 0x80(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x4760
jmp 0x24f8
callq 0x2060
movq %rax, 0x78(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x26b0
movq %rax, 0x30(%rsp)
jmp 0x251b
movq 0x30(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x2680
movq %rax, 0x28(%rsp)
jmp 0x2536
movq 0x28(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x2700
movq %rax, 0x20(%rsp)
jmp 0x2551
movq 0x20(%rsp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x9aa5(%rip), %xmm1     # 0xc008
mulsd %xmm1, %xmm0
movsd %xmm0, 0x70(%rsp)
movl 0x8c(%rsp), %esi
incl %esi
movsd 0x70(%rsp), %xmm0
leaq 0x9aab(%rip), %rdi      # 0xc02e
movb $0x1, %al
callq 0x2050
jmp 0x258c
jmp 0x258e
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0x24c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x2880
jmp 0x266c
callq 0x2060
movq %rax, 0x58(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x26b0
movq %rax, 0x18(%rsp)
jmp 0x25ed
movq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x2680
movq %rax, 0x10(%rsp)
jmp 0x2608
movq 0x10(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x2700
movq %rax, 0x8(%rsp)
jmp 0x2623
movq 0x8(%rsp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x99d3(%rip), %xmm1     # 0xc008
mulsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x50(%rsp), %xmm0
leaq 0x9a05(%rip), %rdi      # 0xc051
movb $0x1, %al
callq 0x2050
jmp 0x2655
leaq 0xa8(%rsp), %rdi
callq 0x2880
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
retq
movq 0xa0(%rsp), %rdi
callq 0x22a0
nopl (%rax)