// File: attractivechaos[P]udb2/khashlpp/./../common.c
// Function: main
int main(int argc, char *argv[])
{
	uint32_t test_int(uint32_t n, uint32_t x0);
	int c;
	double t, t0;
	uint32_t i, m = 5, max = 50000000, n = 10000000, x0 = 1, step;
	uint64_t sum;
	long m0;

	while ((c = getopt(argc, argv, "n:x:0:k:")) >= 0) {
		if (c == 'n') n = atol(optarg);
		else if (c == 'x') max = atol(optarg);
		else if (c == '0') x0 = atol(optarg);
		else if (c == 'k') m = atoi(optarg);
	}

	t = cputime();
	sum = traverse_rng(max, x0);
	t0 = cputime() - t;
	fprintf(stderr, "CPU time spent on RNG: %.3f sec; total sum: %lu\n", t0, (unsigned long)sum);
	m0 = peakrss();

	step = (max - n) / m;
	for (i = 0; i <= m; ++i, n += step) {
		double t, mem, tpm;
		uint32_t size;
		t = cputime();
		size = test_int(n, x0);
		t = cputime() - t;
		mem = peakrss() - m0;
		tpm = (t - t0 * n / max) / n * 1e6;
		printf("%d\t%d\t%.3f\t%.3f\t%.4f\t%.4f\n", i, n, t, mem/1024./1024., tpm, mem / size);
	}
	return 0;
}

// Assembly:
subq $0x78, %rsp
movl $0x0, 0x74(%rsp)
movl %edi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movl $0x5, 0x48(%rsp)
movl $0x2faf080, 0x44(%rsp)  # imm = 0x2FAF080
movl $0x989680, 0x40(%rsp)   # imm = 0x989680
movl $0x1, 0x3c(%rsp)
movl 0x70(%rsp), %edi
movq 0x68(%rsp), %rsi
leaq 0xcfb(%rip), %rdx       # 0x2020
callq 0x1040
movl %eax, 0x64(%rsp)
cmpl $0x0, %eax
jl 0x13ac
cmpl $0x6e, 0x64(%rsp)
jne 0x134f
movq 0x2c8f(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
callq 0x1080
movl %eax, 0x40(%rsp)
jmp 0x13a7
cmpl $0x78, 0x64(%rsp)
jne 0x136b
movq 0x2c73(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
callq 0x1080
movl %eax, 0x44(%rsp)
jmp 0x13a5
cmpl $0x30, 0x64(%rsp)
jne 0x1387
movq 0x2c57(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
callq 0x1080
movl %eax, 0x3c(%rsp)
jmp 0x13a3
cmpl $0x6b, 0x64(%rsp)
jne 0x13a1
movq 0x2c3b(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
callq 0x10b0
movl %eax, 0x48(%rsp)
jmp 0x13a3
jmp 0x13a5
jmp 0x13a7
jmp 0x1315
callq 0x1530
movsd %xmm0, 0x58(%rsp)
movl 0x44(%rsp), %edi
movl 0x3c(%rsp), %esi
callq 0x11e0
movq %rax, 0x30(%rsp)
callq 0x1530
subsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x2bff(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
movsd 0x50(%rsp), %xmm0
movq 0x30(%rsp), %rdx
leaq 0xc33(%rip), %rsi       # 0x2029
movb $0x1, %al
callq 0x10a0
callq 0x1580
movq %rax, 0x28(%rsp)
movl 0x44(%rsp), %eax
subl 0x40(%rsp), %eax
xorl %edx, %edx
divl 0x48(%rsp)
movl %eax, 0x38(%rsp)
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x48(%rsp), %eax
ja 0x151c
callq 0x1530
movsd %xmm0, 0x20(%rsp)
movl 0x40(%rsp), %edi
movl 0x3c(%rsp), %esi
callq 0x15b0
movl %eax, 0xc(%rsp)
callq 0x1530
movsd 0x20(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x1580
movq 0x28(%rsp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x20(%rsp), %xmm0
movsd 0x50(%rsp), %xmm2
movl 0x40(%rsp), %eax
cvtsi2sd %rax, %xmm1
mulsd %xmm1, %xmm2
movl 0x44(%rsp), %eax
cvtsi2sd %rax, %xmm3
divsd %xmm3, %xmm2
subsd %xmm2, %xmm0
divsd %xmm1, %xmm0
movsd 0xb5a(%rip), %xmm1      # 0x2008
mulsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movl 0x4c(%rsp), %esi
movl 0x40(%rsp), %edx
movsd 0x20(%rsp), %xmm0
movsd 0x18(%rsp), %xmm3
movsd 0xb3c(%rip), %xmm2      # 0x2010
movaps %xmm3, %xmm1
mulsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
movsd 0x10(%rsp), %xmm2
movl 0xc(%rsp), %eax
cvtsi2sd %rax, %xmm4
divsd %xmm4, %xmm3
leaq 0xb61(%rip), %rdi       # 0x205a
movb $0x4, %al
callq 0x1030
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
movl 0x38(%rsp), %eax
addl 0x40(%rsp), %eax
movl %eax, 0x40(%rsp)
jmp 0x1421
xorl %eax, %eax
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)