// File: /workspace/github_c_makefile_star2_O0/ranbenbasat[P]RHHH/randmain1.c
// Function: main
int main(int argc, char * argv[]) {
		int m; //number of heavy hitters in output
		int counters = 100;
		int threshold = 1000;
		int n = 100000;
		double time, walltime;
		double epsil;
		HeavyHitter * ans;
		int i,j;
		unsigned int w, x, y, z;
		clock_t begint, endt;
		struct timeb begintb, endtb;
		unsigned int ip;
		unsigned int * data;
		double insertProb = 1. / VMULT;	
		double measurements[NRRUNS] = {0};
		double t_4 = 2.572; //Change if NRRUNS!=5
		double avg = 0, stdev = 0, upCI = 0, dnCI= 0, sos = 0;
		FILE * fp = NULL; //the file for the output
		FILE * fsummary = NULL;
		if (getenv("SUMMARYFILE") != NULL) fsummary = fopen(getenv("SUMMARYFILE"), "a");

		if (argc > 1) n = atoi(argv[1]);
		if (argc > 2) counters = atoi(argv[2]);
		if (argc > 3) threshold = atoi(argv[3]);
		if (argc > 4) fp = fopen(argv[4], "w");

		if(n/counters >= threshold) {
			printf("Unacceptable parameters: eps*n >= theshold\n");
			return 0;
		}

		data = (unsigned int *) malloc(sizeof(unsigned int) * n);

		for (i = 0; i < n; i++) {
			scanf("%d%d%d%d", &w, &x, &y, &z);
			ip = (unsigned int)256*((unsigned int)256*((unsigned int)256*w + x) + y) + z;
			data[i] = ip;
		}

		for (j=0; j < NRRUNS; ++j){
			init((double)1/(double)counters, insertProb);
			begint = clock();
			ftime(&begintb);
			for (i = 0; i < n; i++){
				update(data[i], 1);
			}
			endt = clock();
			ftime(&endtb);

			time = ((double)(endt-begint))/CLK_PER_SEC;
			walltime = ((double) (endtb.time-begintb.time))+((double)endtb.millitm-(double)begintb.millitm)/1000;
			measurements[j] = time;
			avg += time;
			if (j < NRRUNS - 1)
				deinit();
		}
		
		avg /= NRRUNS;
		
		for (j=0; j < NRRUNS; ++j){
			sos += pow(measurements[j] - avg, 2);
		}
		stdev = pow(sos / (NRRUNS - 1), 0.5);
		
		upCI = avg + stdev * t_4 / pow(NRRUNS, 0.5) ;
		dnCI = avg - stdev * t_4 / pow(NRRUNS, 0.5) ;


		free(data);

		printf("%d ips took %fs (%fs-%fs) ", n, avg, dnCI, upCI);

		ans = output(threshold, &m, n);

		printf("%d HHHs\n", m);
		
		deinit();


		if (fp != NULL) {
			fprintf(fp, "%s %d %d %d %d %lf\n", argv[0], n, counters, threshold, m, time);
			for (i = 0; i < m; i++) {
				fprintf(fp, "%d %d.%d.%d.%d %d %d\n",
				ans[i].mask,
				(int)((ans[i].item >> 24) & (LCLitem_t)255),
				(int)((ans[i].item >> 16) & (LCLitem_t)255),
				(int)((ans[i].item >> 8) & (LCLitem_t)255),
				(int)((ans[i].item >> 0) & (LCLitem_t)255),
				ans[i].lower * ( (int) (NUM_MASKS / insertProb)), ans[i].upper * ( (int) (NUM_MASKS / insertProb)));				
			}
			fclose(fp);
		}
		
		epsil = -1;
		for (i = 0; i < m; i++) {
			epsil = dblmainmax(epsil, ((double)(ans[i].upper-ans[i].lower))/n );
		}

		free(ans);

		if (fsummary != NULL) {
			fprintf(fsummary, "check=false algorithm=%-14s nitems=%-10d counters=%-5d threshold=%-9d  outputsize=%-3d time=%lf walltime=%lf epsilon=%lf",
			                   argv[0],        n,           counters,     threshold,      m,              time,  walltime, epsil);
			fprintf(fsummary, "\n");
			fclose(fsummary);       
		}

	return 0;
}

// Assembly:
subq $0x148, %rsp            # imm = 0x148
movl $0x0, 0x144(%rsp)
movl %edi, 0x140(%rsp)
movq %rsi, 0x138(%rsp)
movl $0x64, 0x130(%rsp)
movl $0x3e8, 0x12c(%rsp) # imm = 0x3E8
movl $0x186a0, 0x128(%rsp) # imm = 0x186A0
movsd 0x355e(%rip), %xmm0     # 0x5008
movsd %xmm0, 0xa8(%rsp)
leaq 0x80(%rsp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x10b0
movsd 0x3551(%rip), %xmm0     # 0x5020
movsd %xmm0, 0x78(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x70(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x68(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
leaq 0x353d(%rip), %rdi      # 0x5058
callq 0x1030
cmpq $0x0, %rax
je 0x1b46
leaq 0x352b(%rip), %rdi      # 0x5058
callq 0x1030
movq %rax, %rdi
leaq 0x3528(%rip), %rsi      # 0x5064
callq 0x1160
movq %rax, 0x40(%rsp)
cmpl $0x1, 0x140(%rsp)
jle 0x1b68
movq 0x138(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x1190
movl %eax, 0x128(%rsp)
cmpl $0x2, 0x140(%rsp)
jle 0x1b8a
movq 0x138(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1190
movl %eax, 0x130(%rsp)
cmpl $0x3, 0x140(%rsp)
jle 0x1bac
movq 0x138(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x1190
movl %eax, 0x12c(%rsp)
cmpl $0x4, 0x140(%rsp)
jle 0x1bd3
movq 0x138(%rsp), %rax
movq 0x20(%rax), %rdi
leaq 0x349d(%rip), %rsi      # 0x5066
callq 0x1160
movq %rax, 0x48(%rsp)
movl 0x128(%rsp), %eax
cltd
idivl 0x130(%rsp)
cmpl 0x12c(%rsp), %eax
jl 0x1c09
leaq 0x3476(%rip), %rdi      # 0x5068
movb $0x0, %al
callq 0x10a0
movl $0x0, 0x144(%rsp)
jmp 0x22f6
movslq 0x128(%rsp), %rdi
shlq $0x2, %rdi
callq 0x1110
movq %rax, 0xb0(%rsp)
movl $0x0, 0x104(%rsp)
movl 0x104(%rsp), %eax
cmpl 0x128(%rsp), %eax
jge 0x1ccb
leaq 0x344c(%rip), %rdi      # 0x5094
leaq 0xfc(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
leaq 0xf4(%rsp), %rcx
leaq 0xf0(%rsp), %r8
movb $0x0, %al
callq 0x1180
movl 0xfc(%rsp), %eax
shll $0x8, %eax
addl 0xf8(%rsp), %eax
shll $0x8, %eax
addl 0xf4(%rsp), %eax
shll $0x8, %eax
addl 0xf0(%rsp), %eax
movl %eax, 0xbc(%rsp)
movl 0xbc(%rsp), %edx
movq 0xb0(%rsp), %rax
movslq 0x104(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0x1c2d
movl $0x0, 0x100(%rsp)
cmpl $0x5, 0x100(%rsp)
jge 0x1e58
cvtsi2sdl 0x130(%rsp), %xmm1
movsd 0x3313(%rip), %xmm0     # 0x5008
divsd %xmm1, %xmm0
movsd 0xa8(%rsp), %xmm1
callq 0x1370
callq 0x1080
movq %rax, 0xe8(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x11b0
movl $0x0, 0x104(%rsp)
movl 0x104(%rsp), %eax
cmpl 0x128(%rsp), %eax
jge 0x1d6c
movq 0xb0(%rsp), %rax
movslq 0x104(%rsp), %rcx
movl (%rax,%rcx,4), %edi
movl $0x1, %esi
callq 0x1450
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0x1d2c
callq 0x1080
movq %rax, 0xe0(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x11b0
movq 0xe0(%rsp), %rax
movq 0xe8(%rsp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movsd 0x32aa(%rip), %xmm1     # 0x5050
divsd %xmm1, %xmm0
movsd %xmm0, 0x120(%rsp)
movq 0xc0(%rsp), %rax
movq 0xd0(%rsp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movzwl 0xc8(%rsp), %eax
cvtsi2sd %eax, %xmm1
movzwl 0xd8(%rsp), %eax
cvtsi2sd %eax, %xmm2
subsd %xmm2, %xmm1
movsd 0x3259(%rip), %xmm2     # 0x5048
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x118(%rsp)
movsd 0x120(%rsp), %xmm0
movslq 0x100(%rsp), %rax
movsd %xmm0, 0x80(%rsp,%rax,8)
movsd 0x120(%rsp), %xmm0
addsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
cmpl $0x4, 0x100(%rsp)
jge 0x1e40
movb $0x0, %al
callq 0x1410
jmp 0x1e42
movl 0x100(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x100(%rsp)
jmp 0x1cd6
movsd 0x70(%rsp), %xmm0
movsd 0x31c2(%rip), %xmm1     # 0x5028
divsd %xmm1, %xmm0
movsd %xmm0, 0x70(%rsp)
movl $0x0, 0x100(%rsp)
cmpl $0x5, 0x100(%rsp)
jge 0x1ec8
movslq 0x100(%rsp), %rax
movsd 0x80(%rsp,%rax,8), %xmm0
subsd 0x70(%rsp), %xmm0
movsd 0x316c(%rip), %xmm1     # 0x5010
callq 0x1070
addsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movl 0x100(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x100(%rsp)
jmp 0x1e7b
movsd 0x50(%rsp), %xmm0
movsd 0x3162(%rip), %xmm1     # 0x5038
divsd %xmm1, %xmm0
movsd 0x314e(%rip), %xmm1     # 0x5030
callq 0x1070
movsd %xmm0, 0x68(%rsp)
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x68(%rsp), %xmm0
mulsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x3115(%rip), %xmm0     # 0x5028
movsd 0x3115(%rip), %xmm1     # 0x5030
callq 0x1070
movsd 0x20(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x28(%rsp), %xmm0
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x68(%rsp), %xmm0
mulsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x30c5(%rip), %xmm0     # 0x5028
movsd 0x30c5(%rip), %xmm1     # 0x5030
callq 0x1070
movsd 0x30(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x38(%rsp), %xmm0
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x1040
movl 0x128(%rsp), %esi
movsd 0x70(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
movsd 0x60(%rsp), %xmm2
leaq 0x30e3(%rip), %rdi      # 0x509d
movb $0x3, %al
callq 0x10a0
movl 0x12c(%rsp), %edi
movl 0x128(%rsp), %edx
leaq 0x134(%rsp), %rsi
callq 0x1560
movq %rax, 0x108(%rsp)
movl 0x134(%rsp), %esi
leaq 0x30c6(%rip), %rdi      # 0x50b8
movb $0x0, %al
callq 0x10a0
movb $0x0, %al
callq 0x1410
cmpq $0x0, 0x48(%rsp)
je 0x21c4
movq 0x48(%rsp), %rdi
movq 0x138(%rsp), %rax
movq (%rax), %rdx
movl 0x128(%rsp), %ecx
movl 0x130(%rsp), %r8d
movl 0x12c(%rsp), %r9d
movl 0x134(%rsp), %eax
movsd 0x120(%rsp), %xmm0
leaq 0x3077(%rip), %rsi      # 0x50c1
movl %eax, (%rsp)
movb $0x1, %al
callq 0x1100
movl $0x0, 0x104(%rsp)
movl 0x104(%rsp), %eax
cmpl 0x134(%rsp), %eax
jge 0x21ba
movq 0x48(%rsp), %rdi
movq 0x108(%rsp), %rax
movslq 0x104(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %edx
movq 0x108(%rsp), %rax
movslq 0x104(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %ecx
shrl $0x18, %ecx
andl $0xff, %ecx
movq 0x108(%rsp), %rax
movslq 0x104(%rsp), %rsi
shlq $0x4, %rsi
addq %rsi, %rax
movl (%rax), %r8d
shrl $0x10, %r8d
andl $0xff, %r8d
movq 0x108(%rsp), %rax
movslq 0x104(%rsp), %rsi
shlq $0x4, %rsi
addq %rsi, %rax
movl (%rax), %r9d
shrl $0x8, %r9d
andl $0xff, %r9d
movq 0x108(%rsp), %rax
movslq 0x104(%rsp), %rsi
shlq $0x4, %rsi
addq %rsi, %rax
movl (%rax), %r11d
shrl $0x0, %r11d
andl $0xff, %r11d
movq 0x108(%rsp), %rax
movslq 0x104(%rsp), %rsi
shlq $0x4, %rsi
addq %rsi, %rax
movl 0xc(%rax), %r10d
movsd 0x2ee2(%rip), %xmm0     # 0x5028
divsd 0xa8(%rsp), %xmm0
cvttsd2si %xmm0, %eax
imull %eax, %r10d
movq 0x108(%rsp), %rax
movslq 0x104(%rsp), %rsi
shlq $0x4, %rsi
addq %rsi, %rax
movl 0x8(%rax), %eax
movsd 0x2eaf(%rip), %xmm0     # 0x5028
divsd 0xa8(%rsp), %xmm0
cvttsd2si %xmm0, %esi
imull %esi, %eax
leaq 0x2f45(%rip), %rsi      # 0x50d5
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x1100
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0x205f
movq 0x48(%rsp), %rdi
callq 0x1090
movsd 0x2e74(%rip), %xmm0     # 0x5040
movsd %xmm0, 0x110(%rsp)
movl $0x0, 0x104(%rsp)
movl 0x104(%rsp), %eax
cmpl 0x134(%rsp), %eax
jge 0x225f
movsd 0x110(%rsp), %xmm0
movq 0x108(%rsp), %rax
movslq 0x104(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq 0x108(%rsp), %rcx
movslq 0x104(%rsp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
subl 0xc(%rcx), %eax
cvtsi2sd %eax, %xmm1
cvtsi2sdl 0x128(%rsp), %xmm2
divsd %xmm2, %xmm1
callq 0x1a20
movsd %xmm0, 0x110(%rsp)
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0x21e0
movq 0x108(%rsp), %rdi
callq 0x1040
cmpq $0x0, 0x40(%rsp)
je 0x22eb
movq 0x40(%rsp), %rdi
movq 0x138(%rsp), %rax
movq (%rax), %rdx
movl 0x128(%rsp), %ecx
movl 0x130(%rsp), %r8d
movl 0x12c(%rsp), %r9d
movl 0x134(%rsp), %eax
movsd 0x120(%rsp), %xmm0
movsd 0x118(%rsp), %xmm1
movsd 0x110(%rsp), %xmm2
leaq 0x2e27(%rip), %rsi      # 0x50eb
movl %eax, (%rsp)
movb $0x3, %al
callq 0x1100
movq 0x40(%rsp), %rdi
leaq 0x2e0f(%rip), %rsi      # 0x50e9
movb $0x0, %al
callq 0x1100
movq 0x40(%rsp), %rdi
callq 0x1090
movl $0x0, 0x144(%rsp)
movl 0x144(%rsp), %eax
addq $0x148, %rsp            # imm = 0x148
retq
nopw %cs:(%rax,%rax)
nop