// File: /workspace/github_cpp_makefile_star2_O1/ddunbar[P]PDSample/PDSample.cpp
// Function: main
int main(int argc, char **argv)
{
	int multiplier = 1, minMaxThrows = 1000;
	bool maximize = false;
	bool isTiled = false;
	int relax = 0;
	char *method;
	float radius;
	char *outputPath;
	PDSampler *sampler;
	FILE *output;
	double startTime;
	float elapTime;
	int i, N;

	for (i=1; i<argc; i++) {
		char *arg = argv[i];

		if (strcmp(arg,"-m")==0) {
			maximize = true;
		} else if (strcmp(arg,"-t")==0) {
			isTiled = true;
		} else if (strcmp(arg,"-r")==0) {
			if (i+1<argc) {
				i++;
				relax = atoi(argv[i]);
			} else {
				usage(argv[0]);
			}
		} else if (strcmp(arg,"-N")==0) {
			if (i+1<argc) {
				i++;
				minMaxThrows = atoi(argv[i]);
			} else {
				usage(argv[0]);
			}
		} else if (strcmp(arg,"-M")==0) {
			if (i+1<argc) {
				i++;
				multiplier = atoi(argv[i]);
			} else {
				usage(argv[0]);
			}
		} else {
			break;
		}
	}

	if (i+3!=argc) usage(argv[0]);
	
	method = argv[i++];
	radius = (float) strtod(argv[i++],NULL);
	outputPath = argv[i++];

	if (radius<0.0005 || radius>.2) {
		printf("Radius (%f) is outside allowable range.\n", radius);
		exit(1);
	}

	if (!strcmp(method, "DartThrowing")) {
		sampler = new DartThrowing(radius, isTiled, minMaxThrows, multiplier);
	} else if (!strcmp(method, "BestCandidate")) {
		sampler = new BestCandidate(radius, isTiled, multiplier);
	} else if (!strcmp(method, "Boundary")) {
		sampler = new BoundarySampler(radius, isTiled);
	} else if (!strcmp(method, "Pure")) {
		if (!isTiled) {
			printf("Pure sampler does not support untiled domain.\n");
			exit(1);
		}
		sampler = new PureSampler(radius);
	} else if (!strcmp(method, "LinearPure")) {
		if (!isTiled) {
			printf("LinearPure sampler does not support untiled domain.\n");
			exit(1);
		}
		sampler = new LinearPureSampler(radius);
	} else if (!strcmp(method, "Penrose")) {
		if (isTiled) {
			printf("Penrose sampler does not support tiled domain.\n");
			exit(1);
		}
		sampler = new PenroseSampler(radius);
	} else if (!strcmp(method, "Uniform")) {
		sampler = new UniformSampler(radius);
	} else {
		printf("Unrecognized sampling method (%s).\n", method);
		exit(1);
	}

	startTime = timeInSeconds();
	sampler->complete();
	if (maximize) sampler->maximize();
	for (i=0; i<relax; i++) sampler->relax();
	elapTime = (float) (timeInSeconds() - startTime);

	N = (int) sampler->points.size();
	output = fopen(outputPath,"wb");
	if (!output) {
		printf("Unable to open output file (%s).\n", outputPath);
		exit(1);
	} 

	fwrite(&N, 4, 1, output);
	fwrite(&elapTime, 4, 1, output);
	fwrite(&radius, 4, 1, output);
	fwrite(&isTiled, 4, 1, output);
	for (i=0; i<N; i++) {
		fwrite(&sampler->points[i], 8, 1, output);
	}
	fclose(output);
	printf("Wrote: %s (%d points, %fs, %6.1f pts/s)\n", outputPath, N, elapTime, N/elapTime);

	delete sampler;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, 0x8(%rsp)
movl %edi, %r15d
movb $0x0, 0x3(%rsp)
cmpl $0x2, %edi
jl 0x2a89
movl $0x0, 0x14(%rsp)
movl $0x3e8, 0x18(%rsp)      # imm = 0x3E8
movl $0x1, %ebp
movl $0x1, 0x10(%rsp)
xorl %ebx, %ebx
xorl %r14d, %r14d
movslq %ebp, %rax
movq 0x8(%rsp), %rcx
movq (%rcx,%rax,8), %r12
movq %r12, %rdi
leaq 0x7743(%rip), %rsi      # 0xa0eb
callq 0x2250
testl %eax, %eax
je 0x2a05
movq %r12, %rdi
leaq 0x7733(%rip), %rsi      # 0xa0ee
callq 0x2250
movb $0x1, %r13b
testl %eax, %eax
je 0x2a10
movq %r12, %rdi
leaq 0x7720(%rip), %rsi      # 0xa0f1
callq 0x2250
testl %eax, %eax
je 0x2a15
movq %r12, %rdi
leaq 0x7710(%rip), %rsi      # 0xa0f4
callq 0x2250
testl %eax, %eax
je 0x2a35
movq %r12, %rdi
leaq 0x7700(%rip), %rsi      # 0xa0f7
callq 0x2250
testl %eax, %eax
je 0x2a57
xorl %r13d, %r13d
jmp 0x2a77
movb $0x1, %al
movl %eax, 0x14(%rsp)
movb $0x1, %r13b
jmp 0x2a77
movb $0x1, %r14b
jmp 0x2a77
incl %ebp
cmpl %r15d, %ebp
jge 0x2edf
movslq %ebp, %rax
movq 0x8(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
callq 0x22a0
movl %eax, %ebx
jmp 0x2a77
incl %ebp
cmpl %r15d, %ebp
jge 0x2edf
movslq %ebp, %rax
movq 0x8(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
callq 0x22a0
movl %eax, 0x18(%rsp)
jmp 0x2a77
incl %ebp
cmpl %r15d, %ebp
jge 0x2edf
movslq %ebp, %rax
movq 0x8(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
callq 0x22a0
movl %eax, 0x10(%rsp)
testb %r13b, %r13b
je 0x2aab
incl %ebp
cmpl %r15d, %ebp
jl 0x2992
jmp 0x2aab
movl $0x1, 0x10(%rsp)
movl $0x3e8, 0x18(%rsp)      # imm = 0x3E8
xorl %r14d, %r14d
xorl %ebx, %ebx
movl $0x0, 0x14(%rsp)
movl $0x1, %ebp
movb %r14b, 0x3(%rsp)
leal 0x3(%rbp), %eax
cmpl %r15d, %eax
jne 0x2ee4
movslq %ebp, %r12
movq 0x8(%rsp), %rax
movq (%rax,%r12,8), %r15
movq 0x8(%rax,%r12,8), %rdi
xorl %esi, %esi
callq 0x2130
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x2c(%rsp)
movss %xmm0, 0x4(%rsp)
cvtss2sd %xmm0, %xmm0
movsd 0x7578(%rip), %xmm1     # 0xa068
ucomisd %xmm0, %xmm1
ja 0x2ef1
ucomisd 0x756e(%rip), %xmm0     # 0xa070
ja 0x2ef1
movq 0x8(%rsp), %rax
movq 0x10(%rax,%r12,8), %r14
leaq 0x760a(%rip), %rsi      # 0xa123
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
je 0x2bde
leaq 0x7600(%rip), %rsi      # 0xa130
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
je 0x2c0b
leaq 0x75f7(%rip), %rsi      # 0xa13e
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
je 0x2c34
leaq 0x75ef(%rip), %rsi      # 0xa14d
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
je 0x2c65
leaq 0x75d2(%rip), %rsi      # 0xa147
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
je 0x2c9e
leaq 0x75c6(%rip), %rsi      # 0xa152
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
je 0x2cd7
leaq 0x75b7(%rip), %rsi      # 0xa15a
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
jne 0x2f25
movl $0x13d8, %edi           # imm = 0x13D8
callq 0x21a0
movq %rax, %r15
movq %rax, %rdi
movss 0x4(%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
callq 0x2f74
leaq 0xd0d7(%rip), %rax      # 0xfcb0
jmp 0x2d08
movl $0x13e0, %edi           # imm = 0x13E0
callq 0x21a0
movq %rax, %r15
movzbl 0x3(%rsp), %esi
movq %rax, %rdi
movss 0x4(%rsp), %xmm0
movl 0x18(%rsp), %edx
movl 0x10(%rsp), %ecx
callq 0x40d0
jmp 0x2d0f
movl $0x13e0, %edi           # imm = 0x13E0
callq 0x21a0
movq %rax, %r15
movzbl 0x3(%rsp), %esi
movq %rax, %rdi
movss 0x4(%rsp), %xmm0
movl 0x10(%rsp), %edx
callq 0x41cc
jmp 0x2d0f
movl $0x13d8, %edi           # imm = 0x13D8
callq 0x21a0
movq %rax, %r15
movzbl 0x3(%rsp), %esi
movq %rax, %rdi
movss 0x4(%rsp), %xmm0
movl $0x1, %edx
callq 0x2f74
leaq 0xcf50(%rip), %rax      # 0xfbb0
jmp 0x2d08
cmpb $0x0, 0x3(%rsp)
je 0x2f1c
movl $0x13d8, %edi           # imm = 0x13D8
callq 0x21a0
movq %rax, %r15
movq %rax, %rdi
movss 0x4(%rsp), %xmm0
movl $0x1, %esi
movl $0x1, %edx
callq 0x2f74
leaq 0xcf54(%rip), %rax      # 0xfbf0
jmp 0x2d08
cmpb $0x0, 0x3(%rsp)
je 0x2f31
movl $0x13d8, %edi           # imm = 0x13D8
callq 0x21a0
movq %rax, %r15
movq %rax, %rdi
movss 0x4(%rsp), %xmm0
movl $0x1, %esi
movl $0x1, %edx
callq 0x2f74
leaq 0xcf5b(%rip), %rax      # 0xfc30
jmp 0x2d08
cmpb $0x1, 0x3(%rsp)
je 0x2f3a
movl $0x13d8, %edi           # imm = 0x13D8
callq 0x21a0
movq %rax, %r15
movq %rax, %rdi
movss 0x4(%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
callq 0x2f74
leaq 0xcf68(%rip), %rax      # 0xfc70
addq $0x10, %rax
movq %rax, (%r15)
leaq 0x38(%rsp), %r12
leaq 0x30(%rsp), %rsi
movq %r12, %rdi
callq 0x22c0
xorps %xmm0, %xmm0
cvtsi2sdq (%r12), %xmm0
movsd %xmm0, 0x18(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdq 0x8(%r12), %xmm0
divsd 0x731e(%rip), %xmm0     # 0xa060
movsd %xmm0, 0x8(%rsp)
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
testb $0x1, 0x14(%rsp)
je 0x2d60
movq %r15, %rdi
callq 0x3a5e
movsd 0x8(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
testl %ebx, %ebx
jle 0x2d82
movq %r15, %rdi
callq 0x3c74
decl %ebx
jne 0x2d76
leaq 0x38(%rsp), %rbx
leaq 0x30(%rsp), %rsi
movq %rbx, %rdi
callq 0x22c0
xorps %xmm0, %xmm0
cvtsi2sdq (%rbx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq 0x8(%rbx), %xmm1
divsd 0x72b3(%rip), %xmm1     # 0xa060
addsd %xmm0, %xmm1
subsd 0x8(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x24(%rsp)
movq 0x13c0(%r15), %rax
subq 0x13b8(%r15), %rax
shrq $0x3, %rax
movl %eax, 0x28(%rsp)
leaq 0x73a5(%rip), %rsi      # 0xa186
movq %r14, %rdi
callq 0x21f0
testq %rax, %rax
je 0x2f01
movq %rax, %rbx
leaq 0x28(%rsp), %r12
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rax, %rcx
callq 0x2340
leaq 0x24(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2340
leaq 0x2c(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2340
leaq 0x3(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2340
movslq (%r12), %r12
testq %r12, %r12
jle 0x2e8c
leaq (,%r12,8), %r13
xorl %ebp, %ebp
movq 0x13b8(%r15), %rdi
addq %rbp, %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2340
addq $0x8, %rbp
cmpq %rbp, %r13
jne 0x2e67
movq %rbx, %rdi
callq 0x2190
xorps %xmm1, %xmm1
cvtsi2ss %r12d, %xmm1
movss 0x24(%rsp), %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
divss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x72f3(%rip), %rdi      # 0xa1ab
movq %r14, %rsi
movl %r12d, %edx
movb $0x2, %al
callq 0x2040
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb %r14b, 0x3(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rdi
callq 0x28e8
leaq 0x7202(%rip), %rdi      # 0xa0fa
movb $0x1, %al
callq 0x2040
jmp 0x2f12
leaq 0x7281(%rip), %rdi      # 0xa189
movq %r14, %rsi
xorl %eax, %eax
callq 0x2040
movl $0x1, %edi
callq 0x2200
leaq 0x7472(%rip), %rdi      # 0xa395
jmp 0x2f41
leaq 0x7236(%rip), %rdi      # 0xa162
movq %r15, %rsi
jmp 0x2f0b
leaq 0x7457(%rip), %rdi      # 0xa38f
jmp 0x2f41
leaq 0x7482(%rip), %rdi      # 0xa3c3
callq 0x2290
jmp 0x2f12
jmp 0x2f50
jmp 0x2f50
jmp 0x2f50
jmp 0x2f50
movq %rax, %rbx
movl $0x13d8, %esi           # imm = 0x13D8
jmp 0x2f64
jmp 0x2f5c
movq %rax, %rbx
movl $0x13e0, %esi           # imm = 0x13E0
movq %r15, %rdi
callq 0x21b0
movq %rbx, %rdi
callq 0x2310