// File: /workspace/github_c_makefile_star2_O0/ranbenbasat[P]RHHH/main2.c
// Function: main
int main(int argc, char * argv[]) {
		int m; //number of heavy hitters in output
		//scanf("%d%d%d", &counters, &threshold, &n);
		int counters = 100;
		int threshold = 1000;
		int n = 100000;
		double time, walltime;
		double epsil;
		HeavyHitter * ans;
		int i,j;
		int w, x, y, z;
		clock_t begint, endt;
		struct timeb begintb, endtb;
		unsigned long long ip, _ip;
		unsigned long long * data;
		double measurements[NRRUNS] = {0};
		double avg = 0, stdev = 0, upCI = 0, dnCI= 0, sos = 0;		
		double t_4 = 2.572; //Change if NRRUNS!=5
		FILE * fp = NULL;
		FILE * fsummary = NULL; //summary file	
		double insertProb = 1. / VMULT;	
		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 long long *) malloc(sizeof(unsigned long long) * n);

		for (i = 0; i < n; i++) {
			scanf("%d%d%d%d", &w, &x, &y, &z);
			ip = (unsigned long long)256*((unsigned long long)256*((unsigned long long)256*w + x) + y) + z;
			scanf("%d%d%d%d", &w, &x, &y, &z);
			_ip = (unsigned long long)256*((unsigned long long)256*((unsigned long long)256*w + x) + y) + z;
			data[i] = (ip << 32 | _ip);			
		}	
		for (j=0; j < NRRUNS; ++j){
			//printf("j = %d\n", j);
#ifdef RANDHHH
		init((double)1/(double)counters, insertProb);
#else
		init((double)1/(double)counters);
#endif
			begint = clock();
			ftime(&begintb);
			for (i = 0; i < n; i++) {
				update(data[i]);
			}
			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 pairs took %fs (%fs-%fs) ", n, avg, dnCI, upCI);
		ans = output2(threshold, &m);

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

		deinit();

		if (fp != NULL) {
			//fprintf(fp, "%d\n", m);
			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.%d.%d %d %d\n",
				ans[i].mask,
				(int)((ans[i].item >> 56) & (LCLitem_t)255),
				(int)((ans[i].item >> 48) & (LCLitem_t)255),
				(int)((ans[i].item >> 40) & (LCLitem_t)255),
				(int)((ans[i].item >> 32) & (LCLitem_t)255),
				(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),
#ifdef RANDHHH				
				ans[i].lower * ( (int) (NUM_COUNTERS / insertProb)), ans[i].upper * ( (int) (NUM_COUNTERS / insertProb)));
#else
				ans[i].lower, ans[i].upper);
#endif		
			}
			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:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movl $0x0, 0x164(%rsp)
movl %edi, 0x160(%rsp)
movq %rsi, 0x158(%rsp)
movl $0x64, 0x150(%rsp)
movl $0x3e8, 0x14c(%rsp) # imm = 0x3E8
movl $0x186a0, 0x148(%rsp) # imm = 0x186A0
leaq 0xa0(%rsp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x10b0
xorps %xmm0, %xmm0
movsd %xmm0, 0x98(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x90(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x88(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x80(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x101b(%rip), %xmm0     # 0x50d8
movsd %xmm0, 0x70(%rsp)
movq $0x0, 0x68(%rsp)
movq $0x0, 0x60(%rsp)
movsd 0xf2b(%rip), %xmm0      # 0x5008
movsd %xmm0, 0x58(%rsp)
leaq 0x101e(%rip), %rdi      # 0x5108
callq 0x1030
cmpq $0x0, %rax
je 0x4115
leaq 0x100c(%rip), %rdi      # 0x5108
callq 0x1030
movq %rax, %rdi
leaq 0x1009(%rip), %rsi      # 0x5114
callq 0x1160
movq %rax, 0x60(%rsp)
cmpl $0x1, 0x160(%rsp)
jle 0x4137
movq 0x158(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x1190
movl %eax, 0x148(%rsp)
cmpl $0x2, 0x160(%rsp)
jle 0x4159
movq 0x158(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1190
movl %eax, 0x150(%rsp)
cmpl $0x3, 0x160(%rsp)
jle 0x417b
movq 0x158(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x1190
movl %eax, 0x14c(%rsp)
cmpl $0x4, 0x160(%rsp)
jle 0x41a2
movq 0x158(%rsp), %rax
movq 0x20(%rax), %rdi
leaq 0xf7e(%rip), %rsi       # 0x5116
callq 0x1160
movq %rax, 0x68(%rsp)
movl 0x148(%rsp), %eax
cltd
idivl 0x150(%rsp)
cmpl 0x14c(%rsp), %eax
jl 0x41d8
leaq 0xf57(%rip), %rdi       # 0x5118
movb $0x0, %al
callq 0x1090
movl $0x0, 0x164(%rsp)
jmp 0x4a1e
movslq 0x148(%rsp), %rdi
shlq $0x3, %rdi
callq 0x1110
movq %rax, 0xc8(%rsp)
movl $0x0, 0x124(%rsp)
movl 0x124(%rsp), %eax
cmpl 0x148(%rsp), %eax
jge 0x4324
leaq 0xf2d(%rip), %rdi       # 0x5144
leaq 0x11c(%rsp), %rsi
leaq 0x118(%rsp), %rdx
leaq 0x114(%rsp), %rcx
leaq 0x110(%rsp), %r8
movb $0x0, %al
callq 0x1180
movslq 0x11c(%rsp), %rax
shlq $0x8, %rax
movslq 0x118(%rsp), %rcx
addq %rcx, %rax
shlq $0x8, %rax
movslq 0x114(%rsp), %rcx
addq %rcx, %rax
shlq $0x8, %rax
movslq 0x110(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0xd8(%rsp)
leaq 0xec2(%rip), %rdi       # 0x5144
leaq 0x11c(%rsp), %rsi
leaq 0x118(%rsp), %rdx
leaq 0x114(%rsp), %rcx
leaq 0x110(%rsp), %r8
movb $0x0, %al
callq 0x1180
movslq 0x11c(%rsp), %rax
shlq $0x8, %rax
movslq 0x118(%rsp), %rcx
addq %rcx, %rax
shlq $0x8, %rax
movslq 0x114(%rsp), %rcx
addq %rcx, %rax
shlq $0x8, %rax
movslq 0x110(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0xd0(%rsp)
movq 0xd8(%rsp), %rdx
shlq $0x20, %rdx
orq 0xd0(%rsp), %rdx
movq 0xc8(%rsp), %rax
movslq 0x124(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x124(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x124(%rsp)
jmp 0x41fc
movl $0x0, 0x120(%rsp)
cmpl $0x5, 0x120(%rsp)
jge 0x44b0
cvtsi2sdl 0x150(%rsp), %xmm1
movsd 0xcba(%rip), %xmm0      # 0x5008
divsd %xmm1, %xmm0
movsd 0x58(%rsp), %xmm1
callq 0x13d0
callq 0x1070
movq %rax, 0x108(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x11b0
movl $0x0, 0x124(%rsp)
movl 0x124(%rsp), %eax
cmpl 0x148(%rsp), %eax
jge 0x43be
movq 0xc8(%rsp), %rax
movslq 0x124(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1480
movl 0x124(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x124(%rsp)
jmp 0x4382
callq 0x1070
movq %rax, 0x100(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x11b0
movq 0x100(%rsp), %rax
movq 0x108(%rsp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movsd 0xd08(%rip), %xmm1      # 0x5100
divsd %xmm1, %xmm0
movsd %xmm0, 0x140(%rsp)
movq 0xe0(%rsp), %rax
movq 0xf0(%rsp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movzwl 0xe8(%rsp), %eax
cvtsi2sd %eax, %xmm1
movzwl 0xf8(%rsp), %eax
cvtsi2sd %eax, %xmm2
subsd %xmm2, %xmm1
movsd 0xcb7(%rip), %xmm2      # 0x50f8
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x138(%rsp)
movsd 0x140(%rsp), %xmm0
movslq 0x120(%rsp), %rax
movsd %xmm0, 0xa0(%rsp,%rax,8)
movsd 0x140(%rsp), %xmm0
addsd 0x98(%rsp), %xmm0
movsd %xmm0, 0x98(%rsp)
cmpl $0x4, 0x120(%rsp)
jge 0x4498
movb $0x0, %al
callq 0x1440
jmp 0x449a
movl 0x120(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x120(%rsp)
jmp 0x432f
movsd 0x98(%rsp), %xmm0
movsd 0xc1f(%rip), %xmm1      # 0x50e0
divsd %xmm1, %xmm0
movsd %xmm0, 0x98(%rsp)
movl $0x0, 0x120(%rsp)
cmpl $0x5, 0x120(%rsp)
jge 0x4529
movslq 0x120(%rsp), %rax
movsd 0xa0(%rsp,%rax,8), %xmm0
subsd 0x98(%rsp), %xmm0
movsd 0xb0b(%rip), %xmm1      # 0x5010
callq 0x1060
addsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
movl 0x120(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x120(%rsp)
jmp 0x44d9
movsd 0x78(%rsp), %xmm0
movsd 0xbb1(%rip), %xmm1      # 0x50e8
divsd %xmm1, %xmm0
movsd 0xb6d(%rip), %xmm1      # 0x50b0
callq 0x1060
movsd %xmm0, 0x90(%rsp)
movsd 0x98(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x90(%rsp), %xmm0
mulsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0xb63(%rip), %xmm0      # 0x50e0
movsd 0xb2b(%rip), %xmm1      # 0x50b0
callq 0x1060
movsd 0x38(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x40(%rsp), %xmm0
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x98(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x90(%rsp), %xmm0
mulsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0xb0a(%rip), %xmm0      # 0x50e0
movsd 0xad2(%rip), %xmm1      # 0x50b0
callq 0x1060
movsd 0x48(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x50(%rsp), %xmm0
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x80(%rsp)
movq 0xc8(%rsp), %rdi
callq 0x1040
movl 0x148(%rsp), %esi
movsd 0x98(%rsp), %xmm0
movsd 0x80(%rsp), %xmm1
movsd 0x88(%rsp), %xmm2
leaq 0xb14(%rip), %rdi       # 0x514d
movb $0x3, %al
callq 0x1090
movl 0x14c(%rsp), %edi
leaq 0x154(%rsp), %rsi
callq 0x1590
movq %rax, 0x128(%rsp)
movl 0x154(%rsp), %esi
leaq 0xb00(%rip), %rdi       # 0x516a
movb $0x0, %al
callq 0x1090
movb $0x0, %al
callq 0x1440
cmpq $0x0, 0x68(%rsp)
je 0x48ec
movq 0x68(%rsp), %rdi
movq 0x158(%rsp), %rax
movq (%rax), %rdx
movl 0x148(%rsp), %ecx
movl 0x150(%rsp), %r8d
movl 0x14c(%rsp), %r9d
movl 0x154(%rsp), %eax
movsd 0x140(%rsp), %xmm0
leaq 0xab1(%rip), %rsi       # 0x5173
movl %eax, (%rsp)
movb $0x1, %al
callq 0x1100
movl $0x0, 0x124(%rsp)
movl 0x124(%rsp), %eax
cmpl 0x154(%rsp), %eax
jge 0x48e2
movq 0x68(%rsp), %rdi
movq 0x128(%rsp), %rax
movslq 0x124(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq 0x128(%rsp), %rax
movslq 0x124(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x38, %rax
andq $0xff, %rax
movl %eax, %ecx
movq 0x128(%rsp), %rax
movslq 0x124(%rsp), %rsi
imulq $0x18, %rsi, %rsi
addq %rsi, %rax
movq (%rax), %rax
shrq $0x30, %rax
andq $0xff, %rax
movl %eax, %r8d
movq 0x128(%rsp), %rax
movslq 0x124(%rsp), %rsi
imulq $0x18, %rsi, %rsi
addq %rsi, %rax
movq (%rax), %rax
shrq $0x28, %rax
andq $0xff, %rax
movl %eax, %r9d
movq 0x128(%rsp), %rax
movslq 0x124(%rsp), %rsi
imulq $0x18, %rsi, %rsi
addq %rsi, %rax
movq (%rax), %rax
shrq $0x20, %rax
andq $0xff, %rax
movl %eax, %r15d
movq 0x128(%rsp), %rax
movslq 0x124(%rsp), %rsi
imulq $0x18, %rsi, %rsi
addq %rsi, %rax
movq (%rax), %rax
shrq $0x18, %rax
andq $0xff, %rax
movl %eax, %r14d
movq 0x128(%rsp), %rax
movslq 0x124(%rsp), %rsi
imulq $0x18, %rsi, %rsi
addq %rsi, %rax
movq (%rax), %rax
shrq $0x10, %rax
andq $0xff, %rax
movl %eax, %ebp
movq 0x128(%rsp), %rax
movslq 0x124(%rsp), %rsi
imulq $0x18, %rsi, %rsi
addq %rsi, %rax
movq (%rax), %rax
shrq $0x8, %rax
andq $0xff, %rax
movl %eax, %ebx
movq 0x128(%rsp), %rax
movslq 0x124(%rsp), %rsi
imulq $0x18, %rsi, %rsi
addq %rsi, %rax
movq (%rax), %rax
shrq $0x0, %rax
andq $0xff, %rax
movl %eax, %r11d
movq 0x128(%rsp), %rax
movslq 0x124(%rsp), %rsi
imulq $0x18, %rsi, %rsi
addq %rsi, %rax
movl 0x10(%rax), %r10d
movsd 0x88e(%rip), %xmm0      # 0x50f0
divsd 0x58(%rsp), %xmm0
cvttsd2si %xmm0, %eax
imull %eax, %r10d
movq 0x128(%rsp), %rax
movslq 0x124(%rsp), %rsi
imulq $0x18, %rsi, %rsi
addq %rsi, %rax
movl 0xc(%rax), %eax
movsd 0x85e(%rip), %xmm0      # 0x50f0
divsd 0x58(%rsp), %xmm0
cvttsd2si %xmm0, %esi
imull %esi, %eax
leaq 0x8e1(%rip), %rsi       # 0x5187
movl %r15d, (%rsp)
movl %r14d, 0x8(%rsp)
movl %ebp, 0x10(%rsp)
movl %ebx, 0x18(%rsp)
movl %r11d, 0x20(%rsp)
movl %r10d, 0x28(%rsp)
movl %eax, 0x30(%rsp)
movb $0x0, %al
callq 0x1100
movl 0x124(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x124(%rsp)
jmp 0x46d7
movq 0x68(%rsp), %rdi
callq 0x1080
movsd 0x7a4(%rip), %xmm0      # 0x5098
movsd %xmm0, 0x130(%rsp)
movl $0x0, 0x124(%rsp)
movl 0x124(%rsp), %eax
cmpl 0x154(%rsp), %eax
jge 0x4987
movsd 0x130(%rsp), %xmm0
movq 0x128(%rsp), %rax
movslq 0x124(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movq 0x128(%rsp), %rcx
movslq 0x124(%rsp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
subl 0x10(%rcx), %eax
cvtsi2sd %eax, %xmm1
cvtsi2sdl 0x148(%rsp), %xmm2
divsd %xmm2, %xmm1
callq 0x3fe0
movsd %xmm0, 0x130(%rsp)
movl 0x124(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x124(%rsp)
jmp 0x4908
movq 0x128(%rsp), %rdi
callq 0x1040
cmpq $0x0, 0x60(%rsp)
je 0x4a13
movq 0x60(%rsp), %rdi
movq 0x158(%rsp), %rax
movq (%rax), %rdx
movl 0x148(%rsp), %ecx
movl 0x150(%rsp), %r8d
movl 0x14c(%rsp), %r9d
movl 0x154(%rsp), %eax
movsd 0x140(%rsp), %xmm0
movsd 0x138(%rsp), %xmm1
movsd 0x130(%rsp), %xmm2
leaq 0x7bd(%rip), %rsi       # 0x51a9
movl %eax, (%rsp)
movb $0x3, %al
callq 0x1100
movq 0x60(%rsp), %rdi
leaq 0x7a5(%rip), %rsi       # 0x51a7
movb $0x0, %al
callq 0x1100
movq 0x60(%rsp), %rdi
callq 0x1080
movl $0x0, 0x164(%rsp)
movl 0x164(%rsp), %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r14
popq %r15
popq %rbp
retq