// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movl %edi, %r15d
cmpl $0x2, %edi
jl 0x2a3c
movl $0x0, 0x14(%rsp)
movl $0x3e8, 0x18(%rsp)      # imm = 0x3E8
movl $0x1, %r12d
movl $0x1, %ebp
xorl %ebx, %ebx
xorl %r13d, %r13d
movslq %r12d, %rax
movq (%r14,%rax,8), %rax
cmpb $0x2d, (%rax)
jne 0x2a5c
cmpb $0x6d, 0x1(%rax)
jne 0x2995
cmpb $0x0, 0x2(%rax)
je 0x29e9
cmpb $0x74, 0x1(%rax)
jne 0x29a1
cmpb $0x0, 0x2(%rax)
je 0x29f1
cmpb $0x72, 0x1(%rax)
jne 0x29ad
cmpb $0x0, 0x2(%rax)
je 0x29f6
cmpb $0x4e, 0x1(%rax)
jne 0x29b9
cmpb $0x0, 0x2(%rax)
je 0x2a12
cmpb $0x4d, 0x1(%rax)
jne 0x2a5c
cmpb $0x0, 0x2(%rax)
jne 0x2a5c
incl %r12d
cmpl %r15d, %r12d
jge 0x2e87
movslq %r12d, %rax
movq (%r14,%rax,8), %rdi
callq 0x22a0
movl %eax, %ebp
jmp 0x2a2e
movb $0x1, %al
movl %eax, 0x14(%rsp)
jmp 0x2a2e
movb $0x1, %r13b
jmp 0x2a2e
incl %r12d
cmpl %r15d, %r12d
jge 0x2e87
movslq %r12d, %rax
movq (%r14,%rax,8), %rdi
callq 0x22a0
movl %eax, %ebx
jmp 0x2a2e
incl %r12d
cmpl %r15d, %r12d
jge 0x2e87
movslq %r12d, %rax
movq (%r14,%rax,8), %rdi
callq 0x22a0
movl %eax, 0x18(%rsp)
incl %r12d
cmpl %r15d, %r12d
jl 0x2979
jmp 0x2a5c
movl $0x1, %ebp
movl $0x3e8, 0x18(%rsp)      # imm = 0x3E8
xorl %r13d, %r13d
xorl %ebx, %ebx
movl $0x0, 0x14(%rsp)
movl $0x1, %r12d
movb %r13b, 0x7(%rsp)
leal 0x3(%r12), %eax
cmpl %r15d, %eax
jne 0x2e87
movslq %r12d, %r12
movq (%r14,%r12,8), %r15
movq 0x8(%r14,%r12,8), %rdi
xorl %esi, %esi
callq 0x2130
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x2c(%rsp)
movss %xmm0, 0x8(%rsp)
cvtss2sd %xmm0, %xmm0
movsd 0x75ca(%rip), %xmm1     # 0xa068
ucomisd %xmm0, %xmm1
ja 0x2e8f
ucomisd 0x75c0(%rip), %xmm0     # 0xa070
ja 0x2e8f
movq 0x10(%r14,%r12,8), %r14
leaq 0x7652(%rip), %rsi      # 0xa114
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
je 0x2b87
leaq 0x7648(%rip), %rsi      # 0xa121
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
je 0x2bb4
leaq 0x763f(%rip), %rsi      # 0xa12f
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
je 0x2bdd
leaq 0x7637(%rip), %rsi      # 0xa13e
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
je 0x2c10
leaq 0x761a(%rip), %rsi      # 0xa138
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
je 0x2c48
leaq 0x760e(%rip), %rsi      # 0xa143
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
je 0x2c80
leaq 0x75ff(%rip), %rsi      # 0xa14b
movq %r15, %rdi
callq 0x2250
testl %eax, %eax
jne 0x2ec3
movl $0x13d8, %edi           # imm = 0x13D8
callq 0x21a0
movq %rax, %r15
movq %rax, %rdi
movss 0x8(%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
callq 0x2f14
leaq 0xd12e(%rip), %rax      # 0xfcb0
jmp 0x2cb0
movl $0x13e0, %edi           # imm = 0x13E0
callq 0x21a0
movq %rax, %r15
movzbl %r13b, %esi
andl $0x1, %esi
movq %rax, %rdi
movss 0x8(%rsp), %xmm0
movl 0x18(%rsp), %edx
movl %ebp, %ecx
callq 0x3fec
jmp 0x2cb7
movl $0x13e0, %edi           # imm = 0x13E0
callq 0x21a0
movq %rax, %r15
movzbl %r13b, %esi
andl $0x1, %esi
movq %rax, %rdi
movss 0x8(%rsp), %xmm0
movl %ebp, %edx
callq 0x40e4
jmp 0x2cb7
movl $0x13d8, %edi           # imm = 0x13D8
callq 0x21a0
movq %rax, %r15
movzbl %r13b, %esi
andl $0x1, %esi
movq %rax, %rdi
movss 0x8(%rsp), %xmm0
movl $0x1, %edx
callq 0x2f14
leaq 0xcfa5(%rip), %rax      # 0xfbb0
jmp 0x2cb0
testb $0x1, %r13b
je 0x2eba
movl $0x13d8, %edi           # imm = 0x13D8
callq 0x21a0
movq %rax, %r15
movq %rax, %rdi
movss 0x8(%rsp), %xmm0
movl $0x1, %esi
movl $0x1, %edx
callq 0x2f14
leaq 0xcfaa(%rip), %rax      # 0xfbf0
jmp 0x2cb0
testb $0x1, %r13b
je 0x2ecf
movl $0x13d8, %edi           # imm = 0x13D8
callq 0x21a0
movq %rax, %r15
movq %rax, %rdi
movss 0x8(%rsp), %xmm0
movl $0x1, %esi
movl $0x1, %edx
callq 0x2f14
leaq 0xcfb2(%rip), %rax      # 0xfc30
jmp 0x2cb0
testb $0x1, %r13b
jne 0x2ed8
movl $0x13d8, %edi           # imm = 0x13D8
callq 0x21a0
movq %rax, %r15
movq %rax, %rdi
movss 0x8(%rsp), %xmm0
xorl %esi, %esi
xorl %edx, %edx
callq 0x2f14
leaq 0xcfc0(%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 0x7376(%rip), %xmm0     # 0xa060
movsd %xmm0, 0x8(%rsp)
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
testb $0x1, 0x14(%rsp)
je 0x2d08
movq %r15, %rdi
callq 0x397a
movsd 0x8(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
testl %ebx, %ebx
jle 0x2d2a
movq %r15, %rdi
callq 0x3b90
decl %ebx
jne 0x2d1e
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 0x730b(%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 0x73ee(%rip), %rsi      # 0xa177
movq %r14, %rdi
callq 0x21f0
testq %rax, %rax
je 0x2e9f
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 0x7(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2340
movslq (%r12), %r12
testq %r12, %r12
jle 0x2e34
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 0x2e0f
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 0x733c(%rip), %rdi      # 0xa19c
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
movq (%r14), %rdi
callq 0x28d8
leaq 0x7255(%rip), %rdi      # 0xa0eb
movb $0x1, %al
callq 0x2040
jmp 0x2eb0
leaq 0x72d4(%rip), %rdi      # 0xa17a
movq %r14, %rsi
xorl %eax, %eax
callq 0x2040
movl $0x1, %edi
callq 0x2200
leaq 0x74c5(%rip), %rdi      # 0xa386
jmp 0x2edf
leaq 0x7289(%rip), %rdi      # 0xa153
movq %r15, %rsi
jmp 0x2ea9
leaq 0x74aa(%rip), %rdi      # 0xa380
jmp 0x2edf
leaq 0x74d5(%rip), %rdi      # 0xa3b4
callq 0x2290
jmp 0x2eb0
jmp 0x2eee
jmp 0x2eee
jmp 0x2eee
jmp 0x2eee
movq %rax, %rbx
movl $0x13d8, %esi           # imm = 0x13D8
jmp 0x2f02
jmp 0x2efa
movq %rax, %rbx
movl $0x13e0, %esi           # imm = 0x13E0
movq %r15, %rdi
callq 0x21b0
movq %rbx, %rdi
callq 0x2310
nop