// File: sunweilun[P]Delaunay/main.cpp
// Function: main
int main(int argc, char** argv)
{
    char path[1024];
    char inputPath[1024];
    char outputPath[1024];
    outputPath[0] = inputPath[0] = 0;
    bool timing = false;
    bool disp = false;
    int seed = 0;
    int c;
    mesh.setRandomizeFlag(false);
    while((c = getopt(argc, argv, "wcdr::ti:o:")) != -1)
    {
        switch(c)
        {
        case 'd':
            disp = true;
            break;
        case 'i':
            sprintf(inputPath, "%s", optarg);
            break;
        case 'o':
            sprintf(outputPath, "%s", optarg);
            break;
        case 't':
            timing = true;
            break;
        case 'r':
            mesh.setRandomizeFlag(true);
            if(optarg == NULL)
            {
                struct timeval t;
                gettimeofday(&t, NULL);
                mesh.setSeed(unsigned(t.tv_sec*1e6+t.tv_usec));
            }
            else
            {
                seed = atoi(optarg);
                mesh.setSeed(unsigned(seed));
            }
            break;
        case 'w':
            mesh.setMethod(WALKING);
            break;
        case 'c':
            mesh.setMethod(CONFLICT_GRAPH);
            break;
        }
    }
	if(strlen(inputPath) == 0)
	{
		printf("Invalid input path. To know how to use it, please refer to the document.\n");
		return 0;
	}
    std::vector<vec3> v = mesh.loadNodes(inputPath);
    struct timeval ts, te;
    gettimeofday(&ts, NULL);
    mesh.delaunay(v);
    gettimeofday(&te, NULL);
    double dt = (te.tv_sec-ts.tv_sec)*1e6;
    dt += (te.tv_usec-ts.tv_usec);
    if(timing)
        printf("time = %0.3fs\n", dt/(1e6));
    if(strlen(outputPath) > 0)
    {
        sprintf(path, "%s.node", outputPath);
        mesh.outputNodes(path);
        sprintf(path, "%s.ele", outputPath);
        mesh.outputElements(path);
    }
	if(disp)
	{
#if DISPLAY    
        glDisplay(argc, argv);
#endif
	}
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xcb0, %rsp            # imm = 0xCB0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x810(%rbp)
movb $0x0, -0xc10(%rbp)
movb $0x0, -0xc11(%rbp)
movb $0x0, -0xc12(%rbp)
movl $0x0, -0xc18(%rbp)
leaq 0xb54a(%rip), %rdi      # 0x1d110
xorl %esi, %esi
callq 0x11f60
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x17e9(%rip), %rdx      # 0x133c4
callq 0x1050
movl %eax, -0xc1c(%rbp)
cmpl $-0x1, %eax
je 0x11d35
movl -0xc1c(%rbp), %eax
addl $-0x63, %eax
movl %eax, %ecx
movq %rcx, -0xc88(%rbp)
subl $0x14, %eax
ja 0x11d30
movq -0xc88(%rbp), %rax
leaq 0x1758(%rip), %rcx      # 0x13370
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x1, -0xc12(%rbp)
jmp 0x11d30
leaq -0x810(%rbp), %rdi
movq 0xb39d(%rip), %rax      # 0x1cfd8
movq (%rax), %rdx
leaq 0x178b(%rip), %rsi      # 0x133d0
movb $0x0, %al
callq 0x1040
jmp 0x11d30
leaq -0xc10(%rbp), %rdi
movq 0xb379(%rip), %rax      # 0x1cfd8
movq (%rax), %rdx
leaq 0x1767(%rip), %rsi      # 0x133d0
movb $0x0, %al
callq 0x1040
jmp 0x11d30
movb $0x1, -0xc11(%rbp)
jmp 0x11d30
leaq 0xb488(%rip), %rdi      # 0x1d110
movl $0x1, %esi
callq 0x11f60
movq 0xb33f(%rip), %rax      # 0x1cfd8
cmpq $0x0, (%rax)
jne 0x11ce6
xorl %eax, %eax
movl %eax, %esi
leaq -0xc30(%rbp), %rdi
callq 0x1190
cvtsi2sdq -0xc30(%rbp), %xmm0
cvtsi2sdq -0xc28(%rbp), %xmm1
movsd 0x169f(%rip), %xmm2     # 0x13368
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, %esi
leaq 0xb431(%rip), %rdi      # 0x1d110
callq 0x11f80
jmp 0x11d0d
movq 0xb2eb(%rip), %rax      # 0x1cfd8
movq (%rax), %rdi
callq 0x1180
movl %eax, -0xc18(%rbp)
movl -0xc18(%rbp), %esi
leaq 0xb408(%rip), %rdi      # 0x1d110
callq 0x11f80
jmp 0x11d30
leaq 0xb3fa(%rip), %rdi      # 0x1d110
xorl %esi, %esi
callq 0x11fa0
jmp 0x11d30
leaq 0xb3ea(%rip), %rdi      # 0x1d110
movl $0x1, %esi
callq 0x11fa0
jmp 0x11bcd
leaq -0x810(%rbp), %rdi
callq 0x1090
cmpq $0x0, %rax
jne 0x11d61
leaq 0x1685(%rip), %rdi      # 0x133d3
movb $0x0, %al
callq 0x1030
movl $0x0, -0x4(%rbp)
jmp 0x11efc
leaq 0xb3a8(%rip), %rsi      # 0x1d110
movq %rsi, -0xc98(%rbp)
leaq -0xc48(%rbp), %rdi
movq %rdi, -0xc90(%rbp)
leaq -0x810(%rbp), %rdx
callq 0x3900
xorl %eax, %eax
movl %eax, %esi
leaq -0xc58(%rbp), %rdi
callq 0x1190
movq -0xc98(%rbp), %rdi
movq -0xc90(%rbp), %rsi
callq 0x3e90
jmp 0x11dae
leaq -0xc68(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1190
movq -0xc68(%rbp), %rax
subq -0xc58(%rbp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x158f(%rip), %xmm1     # 0x13368
mulsd %xmm1, %xmm0
movsd %xmm0, -0xc80(%rbp)
movq -0xc60(%rbp), %rax
subq -0xc50(%rbp), %rax
cvtsi2sd %rax, %xmm0
addsd -0xc80(%rbp), %xmm0
movsd %xmm0, -0xc80(%rbp)
testb $0x1, -0xc11(%rbp)
je 0x11e5a
movsd -0xc80(%rbp), %xmm0
movsd 0x1547(%rip), %xmm1     # 0x13368
divsd %xmm1, %xmm0
leaq 0x15f1(%rip), %rdi      # 0x1341d
movb $0x1, %al
callq 0x1030
jmp 0x11e35
jmp 0x11e5a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc70(%rbp)
movl %eax, -0xc74(%rbp)
leaq -0xc48(%rbp), %rdi
callq 0x42e0
jmp 0x11f08
leaq -0xc10(%rbp), %rdi
callq 0x1090
cmpq $0x0, %rax
jbe 0x11ede
leaq 0x15b9(%rip), %rsi      # 0x1342c
xorl %eax, %eax
leaq -0x410(%rbp), %rdi
movq %rdi, -0xca0(%rbp)
leaq -0xc10(%rbp), %rdx
callq 0x1040
movq -0xca0(%rbp), %rsi
leaq 0xb273(%rip), %rdi      # 0x1d110
callq 0x3ae0
jmp 0x11ea4
leaq 0x1589(%rip), %rsi      # 0x13434
xorl %eax, %eax
leaq -0x410(%rbp), %rdi
movq %rdi, -0xca8(%rbp)
leaq -0xc10(%rbp), %rdx
callq 0x1040
movq -0xca8(%rbp), %rsi
leaq 0xb23b(%rip), %rdi      # 0x1d110
callq 0x3c10
jmp 0x11edc
jmp 0x11ede
testb $0x1, -0xc12(%rbp)
je 0x11ee9
jmp 0x11ee9
movl $0x0, -0x4(%rbp)
leaq -0xc48(%rbp), %rdi
callq 0x42e0
movl -0x4(%rbp), %eax
addq $0xcb0, %rsp            # imm = 0xCB0
popq %rbp
retq
movq -0xc70(%rbp), %rdi
callq 0x11c0
nopw %cs:(%rax,%rax)
nop