// File: /workspace/github_c_makefile_star2_O2/Openvario[P]sensord/compdata.c
// Function: main
int main (int argc, char **argv) {

	// local variables
	int iter=300,ch,pos=0,oldpos=0,i=0;
	double pf[2][3], rmserr[2][3];
	char valstr[5]={'0','3','0','0',0};
	char goodbadstr[2][21] = {{0x1b,'[','3','2','m','G','O','O','D',0x1b,'[','0','m',0},{0x1b,'[','3','1','m','B','A','D',0x1b,'[','0','m',0,0}};
	char colors[2][6] ={{0x1b,'[','0','m',0},{0x1b,'[','3','1','m',0}};
	// signals and action handlers
	struct sigaction sigact;

	// socket communication

	// initialize variables
	static_sensor.offset = 0.0;
	static_sensor.linearity = 1.0;
	static_sensor.address = 0x76;
	static_sensor.bus = 1;

	tep_sensor.offset = 0.0;
	tep_sensor.linearity = 1.0;
	tep_sensor.Pcomp2 = static_sensor.Pcomp2 = -0.0000004638;
	tep_sensor.Pcomp1 = static_sensor.Pcomp1 =  0.9514328801;
	tep_sensor.Pcomp0 = static_sensor.Pcomp0 =  0.1658634996;
	tep_sensor.address = 0x77;
	tep_sensor.bus = 1;

	config.timing_log  = 0.06666666666;
	config.timing_mult = 50;
	config.timing_off  = 12;

	//parse command line arguments
	cmdline_parser(argc, argv, &io_mode);

	// get config file options
	if (fp_config != NULL) {
		cfgfile_parser(fp_config, &static_sensor, &tep_sensor, &dynamic_sensor, &voltage_sensor, &temp_sensor, &config);
		fclose(fp_config);
	}

	// check if we are a daemon or stay in foreground
	// stay in foreground
	// install signal handler for CTRL-C
	sigact.sa_handler = sigintHandler;
	sigemptyset (&sigact.sa_mask);
	sigact.sa_flags = 0;
	sigaction(SIGINT, &sigact, NULL);

	// open console again, but as file_pointer
	setbuf(stderr, NULL);

	// ignore SIGPIPE
	signal(SIGPIPE, SIG_IGN);
	// we need hardware sensors for running !!
	// open sensor for static pressure
	/// @todo remove hardcoded i2c address static pressure

	struct termios tio, tio2;

	tcgetattr( 0, &tio );
	tcgetattr( 0, &tio2 );
	tio.c_lflag &= (~ICANON & ~ECHO);
	tcsetattr( 0, TCSANOW, &tio );

	printf ("This program calculates compensation data to compensate for timing glitches on the static and tek sensors.\nThe pressure sensors are sensitive to air movement.\nFor best results, ensure the air is as still as possible when taking measurements.\nHow many thousand data points? %s\033[4D",valstr);
	do {
		ch=getc(stdin);
		if (ch==0x1b)
			if (getc(stdin)==0x5b)
				ch=getc(stdin)+256;
		if ((ch==0x143) && (pos<3)) pos++;
		if ((ch==0x144) && (pos>0)) pos--;
		if (ch==0x141)
			switch (pos) {
				case 0: iter+=1000;
					break;
				case 1: iter+=100;
					break;
				case 2: iter+=10;
					break;
				case 3: iter+=1;
					break;
			}
		if (ch==0x142)
			switch (pos) {
				case 0: iter-=1000;
					break;
				case 1: iter-=100;
					break;
				case 2: iter-=10;
					break;
				case 3: iter-=1;
					break;
			}
		if ((ch>='0') && (ch<='9')) {
			valstr[pos]=ch;
			sscanf (valstr,"%d",&iter);
		}
		if (iter<1) iter=1;
		if (iter>1000) iter=1000;
		sprintf (valstr,"%04d",iter);
		for (i=0;i<oldpos;++i) printf ("\033[1D");
		printf ("%s",valstr);
		for (i=0;i<(4-pos);++i) printf("\033[1D");
		oldpos=pos;
	} while (ch!=0xa);
	printf ("\033[1C\n");
	if (iter>1000) iter=1000;
	iter*=1000;
	printf ("Collecting %d data points.\n",iter);

	tcgetattr( 0, &tio );
	tio.c_lflag |= ICANON | ECHO;
	tcsetattr( 0, TCSANOW, &tio );

	if (ms5611_open(&static_sensor) != 0)
	{
		fprintf(stderr, "Open static sensor failed !!\n");
		return 1;
	}

	//initialize static pressure sensor
	ms5611_reset(&static_sensor);
	usleep(10000);
	ms5611_init(&static_sensor);
	static_sensor.secordcomp = g_secordcomp;
	static_sensor.valid = 1;

	// open sensor for velocity pressure
	if (ms5611_open(&tep_sensor) != 0)
	{
		fprintf(stderr, "Open tep sensor failed !!\n");
		return 1;
	}

	//initialize tep pressure sensor
	ms5611_reset(&tep_sensor);

	usleep(10000);
	ms5611_init(&tep_sensor);
	tep_sensor.secordcomp = g_secordcomp;
	tep_sensor.valid = 1;

	// poll sensors for offset compensation
	tep_sensor.D2f=static_sensor.D2f=0;
	for (i=0;i<120;++i)
	{
		ms5611_start_temp(&static_sensor);
		ms5611_start_temp(&tep_sensor);
		if (i==0) sensor_wait_mark();
		sensor_wait(12500);
		sensor_wait_mark();
		ms5611_read_temp(&static_sensor,0);
		ms5611_read_temp(&tep_sensor,0);
	}

	ms5611_start_pressure(&static_sensor);
	ms5611_start_temp(&tep_sensor);
	sensor_wait(12500);
	sensor_wait_mark();

	ms5611_read_pressure(&static_sensor);
	ms5611_read_temp(&tep_sensor,0);
	ms5611_start_pressure(&tep_sensor);
	ms5611_start_temp(&static_sensor);
	sensor_wait(12500);
	sensor_wait_mark();

	ms5611_read_pressure(&tep_sensor);
	ms5611_read_temp(&static_sensor,0);
	ms5611_calculate_pressure(&tep_sensor);
	ms5611_calculate_pressure(&static_sensor);
	ms5611_start_temp(&tep_sensor);
	ms5611_start_pressure(&static_sensor);
	for (i=0;i<1000;++i)
		pressure_measurement_handler(0);
	// main data acquisition loop

	for (i=0;sidx<iter;)
	{
		if (noglitch>29) sensor_wait(250e3);
		pressure_measurement_handler(1);
		if ((sidx%1000)==0) {
			if (i==0) {
				printf ("%d points collected.\n",sidx);
				i=1;
			}
		} else i=0;
	}
	if (fp_datalog!=NULL) fclose(fp_datalog);
	fp_config  = fopen (config_filename,"a+");

	polyfit (statval, sidx, &pf[0][0],&rmserr[0][0]);
	polyfit (tepval, tidx, &pf[1][0],&rmserr[1][0]);
	pos=0;
	printf ("Total data points (the more the better): static: %d, tek: %d\n",sidx, tidx);
	if (rmserr[0][2]>=80) i=3; else i=0;
	if (rmserr[1][2]>=80) i|=5;
	printf ("%s\tTotal RMS Error (lower is better, ideally below 80): static: %s%f%s, tek: %s%f%s\n",goodbadstr[i&1],colors[(i>>1)&1],rmserr[0][2],colors[0],colors[(i>>2)&1],rmserr[1][2],colors[0]);
	pos|=i;
	if (rmserr[0][0]>=1e-3) i=3; else i=0;
	if (rmserr[1][0]>=1e-3) i|=5;
	printf ("%s\tMean Error (This should be very close to zero): static %s%f%s, tek: %s%f%s\n",goodbadstr[i&1],colors[(i>>1)&1],rmserr[0][0],colors[0],colors[(i>>2)&1],rmserr[1][0],colors[0]);
	pos|=i;
	if (rmserr[0][1]>=80) i=3; else i=0;
	if (rmserr[1][1]>=80) i|=5;
	printf ("%s\tStd Deviation of Error (should be RMS error or slightly less): static: %s%f%s, tek: %s%f%s\n",goodbadstr[i&1],colors[(i>>1)&1],rmserr[0][1],colors[0],colors[(i>>2)&1],rmserr[1][1],colors[0]);
	pos|=i;
	if (urun>0) i=3; else i=0;
	if (orun>0) i|=5;
	if (i) printf ("%s\tGlitches (zero is ideal), Underrun: %s%d%s, Overrun: %s%d%s\n",goodbadstr[1],colors[(i>>1)&1],urun,colors[0],colors[(i>>2)&1],orun,colors[0]);
	else printf ("%s\tNo overruns/underruns errors found during glitches.\n",goodbadstr[0]);
	pos|=i;
	printf ("static_comp %.10lf %.10lf %.10lf\ntek_comp %.10lf %.10lf %.10lf\n",pf[0][0],pf[0][1],pf[0][2],pf[1][0],pf[1][1],pf[1][2]);
	printf ("Empirical testing seems to show: \n");
	if ((2.5e-6<pf[0][0]) || (pf[0][0]<-2.5e-6)) i=3; else i=0;
	if ((2.5e-6<pf[1][0]) || (pf[1][0]<-2.5e-6)) i|=5;
	printf ("%s\t2.5e-6 > quadrature term (%s%4.3e%s and %s%4.3e%s) > -2.5e-6\n",goodbadstr[i&1],colors[(i>>1)&1],pf[0][0],colors[0],colors[(i>>2)&1],pf[1][0],colors[0]);
	pos|=i;
	if ((-.20<pf[0][1]) || (pf[0][1]<-0.35)) i=3; else i=0;
	if ((-.20<pf[1][1]) || (pf[1][1]<-0.35)) i|=5;
	printf ("%s\t-0.20 > linear term (%s%6.5f%s and %s%6.5f%s) > -0.35\n",goodbadstr[i&1],colors[(i>>1)&1],pf[0][1],colors[0],colors[(i>>2)&1],pf[1][1],colors[0]);
	pos|=i;
	if ((0<pf[0][2]) || (pf[0][2]<-50)) i=3; else i=0;
	if ((0<pf[1][2]) || (pf[1][2]<-50)) i|=5;
	printf ("%s\t0 > constant term (%s%6.5f%s and %s%6.5f%s) > -50\n",goodbadstr[i&1],colors[(i>>1)&1],pf[0][2],colors[0],colors[(i>>2)&1],pf[1][2],colors[0]);
	pos=(pos|i)&1;
	if (pos)
		printf ("These results could be better.  Suggest trying again.\n");
	else
		printf ("These results are good.\n");
	if (fp_config!=NULL) {
		tcgetattr( 0, &tio );
		tio.c_lflag &= (~ICANON & ~ECHO);
		tcsetattr( 0, TCSANOW, &tio );
		if (pos) strcpy(valstr,"no "); else strcpy(valstr,"yes");
		printf ("Do you wish to save results? %s\033[3D",valstr);
		do {
			ch=getc(stdin);
			if (ch==0x1b)
				if (getc(stdin)==0x5b)
					ch=getc(stdin)+256;
			switch (ch) {
				case 0x141 : case 0x142 : case 0x143 : case 0x144 : pos ^=1; break;
				case 'n' : case 'N' : pos = 1; ch = 0xa; break;
				case 'y' : case 'Y' : pos = 0; ch = 0xa; break;
				default : break;
			}
			if (pos) strcpy(valstr,"no "); else strcpy(valstr,"yes");
			if (ch==0xa) printf ("%s\n",valstr); else  printf ("%s\033[3D",valstr);
		} while (ch!=0xa);
		tcgetattr( 0, &tio );
		tio.c_lflag |= ICANON | ECHO;
		tcsetattr( 0, TCSANOW, &tio );

		if (pos==0) {
			printf ("Saving...\n");
			fprintf(fp_config,"\nstatic_comp %.10lf %.10lf %.10lf\ntek_comp %.10lf %.10lf %.10lf\n",pf[0][0],pf[0][1],pf[0][2],pf[1][0],pf[1][1],pf[1][2]);
		}
		fclose (fp_config);
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movl $0x12c, 0x4(%rsp)       # imm = 0x12C
movb $0x0, 0x1c(%rsp)
movl $0x30303330, 0x18(%rsp) # imm = 0x30303330
movups 0x3651(%rip), %xmm0     # 0x549a
movups %xmm0, 0x5a(%rsp)
movaps 0x363b(%rip), %xmm0     # 0x5490
movaps %xmm0, 0x50(%rsp)
movaps 0x361f(%rip), %xmm0     # 0x5480
movaps %xmm0, 0x40(%rsp)
movabsq $0x5b1b00006d305b1b, %rax # imm = 0x5B1B00006D305B1B
movq %rax, 0x8(%rsp)
movl $0x6d3133, 0x10(%rsp)   # imm = 0x6D3133
movss 0x3543(%rip), %xmm0     # 0x53c8
movlps %xmm0, 0x6380(%rip)     # 0x820c
movw $0x176, 0x62ef(%rip)    # imm = 0x176
movlps %xmm0, 0x6410(%rip)     # 0x82ac
movaps 0x353d(%rip), %xmm0     # 0x53e0
movups %xmm0, 0x632e(%rip)     # 0x81d8
movups %xmm0, 0x63c7(%rip)     # 0x8278
movabsq $0x3fc53b03e130e8f3, %rax # imm = 0x3FC53B03E130E8F3
movq %rax, 0x6326(%rip)      # 0x81e8
movq %rax, 0x63bf(%rip)      # 0x8288
movw $0x177, 0x6352(%rip)    # imm = 0x177
movapd 0x3516(%rip), %xmm0     # 0x53f0
movupd %xmm0, 0x63ee(%rip)     # 0x82d0
movabsq $0x4028000000000000, %rax # imm = 0x4028000000000000
movq %rax, 0x63ed(%rip)      # 0x82e0
leaq 0x63ee(%rip), %rdx      # 0x82e8
callq 0x3404
leaq 0x30064c2(%rip), %rbx   # 0x30083c8
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x1f4c
subq $0x8, %rsp
leaq 0x63a7(%rip), %rax      # 0x82c0
leaq 0x6260(%rip), %rsi      # 0x8180
leaq 0x62f9(%rip), %rdx      # 0x8220
leaq 0x63be(%rip), %rcx      # 0x82ec
leaq 0x63df(%rip), %r8       # 0x8314
leaq 0x63f4(%rip), %r9       # 0x8330
pushq %rax
callq 0x37ac
popq %rcx
popq %rdx
movq (%rbx), %rdi
callq 0x10b0
leaq 0xb68(%rip), %rax       # 0x2abb
leaq 0x178(%rsp), %rbx
movq %rax, -0x8(%rbx)
movq %rbx, %rdi
callq 0x1160
andl $0x0, 0x80(%rbx)
xorl %ebp, %ebp
pushq $0x2
popq %rdi
leaq 0x170(%rsp), %rsi
xorl %edx, %edx
callq 0x1080
movq 0x606f(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
xorl %esi, %esi
callq 0x10c0
pushq $0xd
popq %rdi
pushq $0x1
popq %rsi
callq 0x1140
leaq 0xc4(%rsp), %rbx
xorl %edi, %edi
movq %rbx, %rsi
callq 0x11a0
leaq 0x134(%rsp), %rsi
xorl %edi, %edi
callq 0x11a0
andb $-0xb, 0xc(%rbx)
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x11b0
leaq 0x34e5(%rip), %rdi      # 0x54bb
leaq 0x18(%rsp), %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10d0
movq 0x5fdc(%rip), %r14      # 0x7fc8
leaq 0x35e5(%rip), %r12      # 0x55d8
xorl %r15d, %r15d
movq (%r14), %rdi
callq 0x1260
movl %eax, %r13d
cmpl $0x1b, %eax
jne 0x202b
movq (%r14), %rdi
callq 0x1260
pushq $0x1b
popq %rcx
movl %ecx, %r13d
cmpl $0x5b, %eax
jne 0x202b
movq (%r14), %rdi
callq 0x1260
movl %eax, %r13d
addl $0x100, %r13d           # imm = 0x100
cmpl $0x143, %r13d           # imm = 0x143
sete %al
cmpl $0x3, %r15d
setl %cl
andb %al, %cl
movzbl %cl, %r14d
addl %r15d, %r14d
cmpl $0x144, %r13d           # imm = 0x144
sete %al
testl %r14d, %r14d
setg %cl
andb %al, %cl
movzbl %cl, %eax
subl %eax, %r14d
movl %r14d, %eax
cmpl $0x142, %r13d           # imm = 0x142
je 0x2093
cmpl $0x141, %r13d           # imm = 0x141
jne 0x20b6
cmpl $0x3, %r14d
ja 0x20dd
leaq 0x33f1(%rip), %rcx      # 0x5470
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x4(%rsp), %edx
movl $0x3e8, %eax            # imm = 0x3E8
jmp 0x20b2
cmpl $0x3, %r14d
ja 0x20dd
leaq 0x33c0(%rip), %rcx      # 0x5460
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x4(%rsp), %edx
movl $0xfffffc18, %eax       # imm = 0xFFFFFC18
addl %eax, %edx
jmp 0x2115
leal -0x30(%r13), %eax
cmpl $0x9, %eax
ja 0x20dd
movslq %r14d, %rax
movb %r13b, 0x18(%rsp,%rax)
movq %rbx, %rdi
leaq 0x3f9b(%rip), %rsi      # 0x606c
leaq 0x4(%rsp), %rdx
xorl %eax, %eax
callq 0x1180
movl 0x4(%rsp), %edx
jmp 0x2119
movl 0x4(%rsp), %edx
addl $0xa, %edx
jmp 0x2115
movl 0x4(%rsp), %edx
addl $-0xa, %edx
jmp 0x2115
movl 0x4(%rsp), %edx
incl %edx
jmp 0x2115
movl 0x4(%rsp), %edx
addl $0x64, %edx
jmp 0x2115
movl 0x4(%rsp), %edx
decl %edx
jmp 0x2115
movl 0x4(%rsp), %edx
addl $-0x64, %edx
movl %edx, 0x4(%rsp)
testl %edx, %edx
jle 0x2134
cmpl $0x3e9, %edx            # imm = 0x3E9
jb 0x213f
movl $0x3e8, 0x4(%rsp)       # imm = 0x3E8
movl $0x3e8, %edx            # imm = 0x3E8
jmp 0x213f
movl $0x1, 0x4(%rsp)
pushq $0x1
popq %rdx
movq %rbx, %rdi
leaq 0x348a(%rip), %rsi      # 0x55d3
xorl %eax, %eax
callq 0x1200
testl %r15d, %r15d
cmovlel %ebp, %r15d
subl $0x1, %r15d
jb 0x2169
movq %r12, %rdi
xorl %eax, %eax
callq 0x10d0
jmp 0x2157
leaq 0x3c6a(%rip), %rdi      # 0x5dda
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10d0
pushq $0x4
popq %r15
subl %r14d, %r15d
testl %r15d, %r15d
cmovlel %ebp, %r15d
negl %r15d
testl %r15d, %r15d
je 0x219f
movq %r12, %rdi
xorl %eax, %eax
callq 0x10d0
incl %r15d
jmp 0x218b
movl %r14d, %r15d
cmpl $0xa, %r13d
movq 0x5e1b(%rip), %r14      # 0x7fc8
jne 0x1ff6
leaq 0x3796(%rip), %rdi      # 0x5950
callq 0x1070
movl 0x4(%rsp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cmpl %ecx, %eax
cmovll %eax, %ecx
imull $0x3e8, %ecx, %esi      # imm = 0x3E8
movl %esi, 0x4(%rsp)
leaq 0x33ff(%rip), %rdi      # 0x55dd
xorl %eax, %eax
callq 0x10d0
leaq 0xc4(%rsp), %rbx
xorl %edi, %edi
movq %rbx, %rsi
callq 0x11a0
orb $0xa, 0xc(%rbx)
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x11b0
leaq 0x5f72(%rip), %rdi      # 0x8180
callq 0x1464
testl %eax, %eax
jne 0x2a73
leaq 0x5f5e(%rip), %rbx      # 0x8180
movq %rbx, %rdi
callq 0x190d
movl $0x2710, %edi           # imm = 0x2710
callq 0x1270
movq %rbx, %rdi
callq 0x15c5
leaq 0x300616f(%rip), %r14   # 0x30083b2
movzbl (%r14), %eax
movl %eax, 0x5fcb(%rip)      # 0x8218
movl $0x1, 0x5fbd(%rip)      # 0x8214
leaq 0x5fc2(%rip), %rdi      # 0x8220
callq 0x1464
testl %eax, %eax
jne 0x2a88
leaq 0x5fae(%rip), %rbx      # 0x8220
movq %rbx, %rdi
callq 0x190d
movl $0x2710, %edi           # imm = 0x2710
callq 0x1270
movq %rbx, %rdi
callq 0x15c5
movzbl (%r14), %eax
movl %eax, 0x6022(%rip)      # 0x82b8
andl $0x0, 0x5f13(%rip)      # 0x81b0
movl $0x1, 0x600d(%rip)      # 0x82b4
andl $0x0, 0x5fa2(%rip)      # 0x8250
pushq $0x78
popq %r15
leaq 0x5ec7(%rip), %r14      # 0x8180
movl %r15d, %ebp
subl $0x1, %ebp
jb 0x2307
movq %r14, %rdi
callq 0x1960
movq %rbx, %rdi
callq 0x1960
cmpl $0x78, %r15d
jne 0x22dc
callq 0x137c
movss 0x30e8(%rip), %xmm0     # 0x53cc
callq 0x138b
callq 0x137c
movq %r14, %rdi
xorl %esi, %esi
callq 0x1a08
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1a08
movl %ebp, %r15d
jmp 0x22bc
leaq 0x5e72(%rip), %rbx      # 0x8180
movq %rbx, %rdi
callq 0x19b3
leaq 0x5f03(%rip), %r14      # 0x8220
movq %r14, %rdi
callq 0x1960
movss 0x309f(%rip), %xmm0     # 0x53cc
callq 0x138b
callq 0x137c
movq %rbx, %rdi
callq 0x1c44
movq %r14, %rdi
xorl %esi, %esi
callq 0x1a08
movq %r14, %rdi
callq 0x19b3
movq %rbx, %rdi
callq 0x1960
movss 0x306b(%rip), %xmm0     # 0x53cc
callq 0x138b
callq 0x137c
movq %r14, %rdi
callq 0x1c44
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1a08
movq %r14, %rdi
callq 0x1cdb
movq %rbx, %rdi
callq 0x1cdb
movq %r14, %rdi
callq 0x1960
movq %rbx, %rdi
callq 0x19b3
movl $0x3e8, %ebx            # imm = 0x3E8
subl $0x1, %ebx
jb 0x23b0
xorl %edi, %edi
callq 0x2b02
jmp 0x23a2
movb $0x1, %r15b
movl 0x5fcf(%rip), %esi      # 0x8388
pushq $0x1
popq %rbx
movl $0x3e8, %ebp            # imm = 0x3E8
leaq 0x326a(%rip), %r14      # 0x5632
cmpl 0x4(%rsp), %esi
jge 0x2420
cmpl $0x1e, 0x5fb7(%rip)     # 0x838c
jl 0x23e4
movss 0x2ff1(%rip), %xmm0     # 0x53d0
callq 0x138b
movl %ebx, %edi
callq 0x2b02
movl 0x5f97(%rip), %esi      # 0x8388
movl %esi, %eax
cltd
idivl %ebp
testl %edx, %edx
setne %r12b
notb %r15b
orb %r12b, %r15b
testb $0x1, %r15b
movl %r12d, %r15d
jne 0x23c8
movq %r14, %rdi
xorl %eax, %eax
callq 0x10d0
movl 0x5f6d(%rip), %esi      # 0x8388
movl %r12d, %r15d
jmp 0x23c8
leaq 0x3005f99(%rip), %rax   # 0x30083c0
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2434
callq 0x10b0
leaq 0x3005f95(%rip), %rdi   # 0x30083d0
leaq 0x3206(%rip), %rsi      # 0x5648
callq 0x11d0
leaq 0x3005f7a(%rip), %rcx   # 0x30083c8
movq %rax, (%rcx)
movl 0x5f31(%rip), %esi      # 0x8388
leaq 0x5f32(%rip), %rdi      # 0x8390
leaq 0x90(%rsp), %rdx
leaq 0x100(%rsp), %rcx
callq 0x3129
movl 0x3005f17(%rip), %esi   # 0x3008390
leaq 0xa8(%rsp), %rdx
leaq 0x118(%rsp), %r15
leaq 0x1805f00(%rip), %rdi   # 0x1808390
movq %r15, %rcx
callq 0x3129
movl 0x5eea(%rip), %esi      # 0x8388
movl 0x3005eec(%rip), %edx   # 0x3008390
leaq 0x31a0(%rip), %rdi      # 0x564b
xorl %eax, %eax
callq 0x10d0
movsd -0x8(%r15), %xmm0
movsd 0x10(%r15), %xmm1
movsd 0x2f5a(%rip), %xmm2     # 0x5420
xorl %eax, %eax
ucomisd %xmm2, %xmm0
setae %al
leal (%rax,%rax,2), %eax
movl %eax, %ebp
orl $0x5, %ebp
ucomisd %xmm2, %xmm1
cmovbl %eax, %ebp
movl %ebp, %eax
andl $0x1, %eax
imulq $0x15, %rax, %rax
leaq (%rsp,%rax), %rsi
addq $0x40, %rsi
movl %ebp, %eax
shrl %eax
andl $0x1, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %rdx
addq $0x8, %rdx
movl %ebp, %eax
shrl $0x2, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %r8
addq $0x8, %r8
leaq 0x316f(%rip), %rdi      # 0x5689
leaq 0x8(%rsp), %r14
movq %r14, %rcx
movq %r14, %r9
movb $0x2, %al
callq 0x10d0
movsd -0x18(%r15), %xmm0
movsd (%r15), %xmm1
movsd 0x2ee9(%rip), %xmm2     # 0x5428
xorl %eax, %eax
ucomisd %xmm2, %xmm0
setae %al
leal (%rax,%rax,2), %eax
movl %eax, %r12d
orl $0x5, %r12d
ucomisd %xmm2, %xmm1
cmovbl %eax, %r12d
movl %r12d, %eax
andl $0x1, %eax
imulq $0x15, %rax, %rax
leaq (%rsp,%rax), %rsi
addq $0x40, %rsi
movl %r12d, %eax
shrl %eax
andl $0x1, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %rdx
addq $0x8, %rdx
movl %r12d, %eax
shrl $0x2, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %r8
addq $0x8, %r8
leaq 0x3145(%rip), %rdi      # 0x56de
movq %r14, %rcx
movq %r14, %r9
movb $0x2, %al
callq 0x10d0
orl %ebp, %r12d
movsd -0x10(%r15), %xmm0
movsd 0x8(%r15), %xmm1
xorl %eax, %eax
movsd 0x2e61(%rip), %xmm2     # 0x5420
ucomisd %xmm2, %xmm0
setae %al
leal (%rax,%rax,2), %eax
movl %eax, %ebp
orl $0x5, %ebp
ucomisd %xmm2, %xmm1
cmovbl %eax, %ebp
movl %ebp, %eax
andl $0x1, %eax
imulq $0x15, %rax, %rax
leaq (%rsp,%rax), %rsi
addq $0x40, %rsi
movl %ebp, %eax
shrl %eax
andl $0x1, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %rdx
addq $0x8, %rdx
movl %ebp, %eax
shrl $0x2, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %r8
addq $0x8, %r8
leaq 0x311c(%rip), %rdi      # 0x572d
movq %r14, %rcx
movq %r14, %r9
movb $0x2, %al
callq 0x10d0
orl %r12d, %ebp
movl 0x3005d6d(%rip), %ecx   # 0x3008394
xorl %eax, %eax
testl %ecx, %ecx
setg %al
leal (%rax,%rax,2), %eax
movl 0x3005d60(%rip), %r10d  # 0x3008398
movl %eax, %r15d
orl $0x5, %r15d
testl %r10d, %r10d
cmovlel %eax, %r15d
testl %r15d, %r15d
je 0x268f
leaq 0x55(%rsp), %rsi
movl %r15d, %eax
shrl %eax
andl $0x1, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %rdx
addq $0x8, %rdx
movl %r15d, %eax
shrl $0x2, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %r9
addq $0x8, %r9
leaq 0x310f(%rip), %rdi      # 0x578c
movq %r14, %r8
xorl %eax, %eax
pushq %r14
pushq %r10
callq 0x10d0
popq %rcx
popq %rdx
jmp 0x26a2
leaq 0x3136(%rip), %rdi      # 0x57cc
leaq 0x40(%rsp), %rsi
xorl %eax, %eax
callq 0x10d0
orl %r15d, %ebp
movsd 0x90(%rsp), %xmm0
movaps %xmm0, 0x80(%rsp)
movsd 0x98(%rsp), %xmm1
movsd %xmm1, 0x38(%rsp)
movsd 0xa0(%rsp), %xmm2
movsd %xmm2, 0x30(%rsp)
movsd 0xa8(%rsp), %xmm3
movaps %xmm3, 0x70(%rsp)
movsd 0xb0(%rsp), %xmm4
movsd %xmm4, 0x28(%rsp)
movsd 0xb8(%rsp), %xmm5
movsd %xmm5, 0x20(%rsp)
leaq 0x31d3(%rip), %rdi      # 0x58da
movb $0x6, %al
callq 0x10d0
leaq 0x3240(%rip), %rdi      # 0x5955
callq 0x1070
movapd 0x2cde(%rip), %xmm0     # 0x5400
movapd 0x80(%rsp), %xmm3
movapd %xmm3, %xmm1
andpd %xmm0, %xmm1
movsd 0x2cf5(%rip), %xmm2     # 0x5430
xorl %eax, %eax
ucomisd %xmm2, %xmm1
seta %al
leal (%rax,%rax,2), %eax
movapd 0x70(%rsp), %xmm1
andpd %xmm1, %xmm0
movl %eax, %r12d
orl $0x5, %r12d
ucomisd %xmm2, %xmm0
cmovbel %eax, %r12d
movl %r12d, %eax
andl $0x1, %eax
imulq $0x15, %rax, %rax
leaq (%rsp,%rax), %rsi
addq $0x40, %rsi
movl %r12d, %eax
shrl %eax
andl $0x1, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %rdx
addq $0x8, %rdx
movl %r12d, %eax
shrl $0x2, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %r8
addq $0x8, %r8
leaq 0x3065(%rip), %rdi      # 0x5804
leaq 0x8(%rsp), %r14
movapd %xmm3, %xmm0
movq %r14, %rcx
movq %r14, %r9
movb $0x2, %al
callq 0x10d0
orl %ebp, %r12d
movsd 0x2c78(%rip), %xmm2     # 0x5438
xorl %eax, %eax
movsd 0x38(%rsp), %xmm0
ucomisd %xmm0, %xmm2
seta %al
movsd 0x2c69(%rip), %xmm1     # 0x5440
ucomisd %xmm1, %xmm0
leal (%rax,%rax,2), %r15d
pushq $0x3
popq %r13
cmoval %r13d, %r15d
movl %r15d, %eax
orl $0x5, %eax
movsd 0x28(%rsp), %xmm3
ucomisd %xmm3, %xmm2
cmoval %eax, %r15d
ucomisd %xmm1, %xmm3
movapd %xmm3, %xmm1
cmoval %eax, %r15d
movl %r15d, %eax
andl $0x1, %eax
imulq $0x15, %rax, %rax
leaq (%rsp,%rax), %rsi
addq $0x40, %rsi
movl %r15d, %eax
shrl %eax
andl $0x1, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %rdx
addq $0x8, %rdx
movl %r15d, %eax
shrl $0x2, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %r8
addq $0x8, %r8
leaq 0x2fff(%rip), %rdi      # 0x5845
movq %r14, %rcx
movq %r14, %r9
movb $0x2, %al
callq 0x10d0
orl %r12d, %r15d
movsd 0x2bea(%rip), %xmm2     # 0x5448
xorl %eax, %eax
movsd 0x30(%rsp), %xmm0
ucomisd %xmm0, %xmm2
seta %al
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
leal (%rax,%rax,2), %ebp
cmoval %r13d, %ebp
movl %ebp, %eax
orl $0x5, %eax
movsd 0x20(%rsp), %xmm3
ucomisd %xmm3, %xmm2
cmoval %eax, %ebp
ucomisd %xmm1, %xmm3
movapd %xmm3, %xmm1
cmoval %eax, %ebp
movl %ebp, %eax
andl $0x1, %eax
imulq $0x15, %rax, %rax
leaq (%rsp,%rax), %rsi
addq $0x40, %rsi
movl %ebp, %eax
shrl %eax
andl $0x1, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %rdx
addq $0x8, %rdx
movl %ebp, %eax
shrl $0x2, %eax
imulq $0x6, %rax, %rax
leaq (%rsp,%rax), %r8
addq $0x8, %r8
leaq 0x2faa(%rip), %rdi      # 0x587f
movq %r14, %rcx
movq %r14, %r9
movb $0x2, %al
callq 0x10d0
orl %r15d, %ebp
andl $0x1, %ebp
leaq 0x3088(%rip), %rax      # 0x5977
leaq 0x3099(%rip), %rdi      # 0x598f
cmoveq %rax, %rdi
callq 0x1070
leaq 0x3005ac2(%rip), %rax   # 0x30083c8
cmpq $0x0, (%rax)
je 0x2a6f
leaq 0xc4(%rsp), %r14
xorl %edi, %edi
movq %r14, %rsi
callq 0x11a0
andb $-0xb, 0xc(%r14)
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
callq 0x11b0
testl %ebp, %ebp
movl $0x736579, %r15d        # imm = 0x736579
movl $0x206f6e, %eax         # imm = 0x206F6E
cmovel %r15d, %eax
leaq 0x18(%rsp), %r14
movl %eax, (%r14)
leaq 0x2f62(%rip), %rdi      # 0x58b5
pushq $0xa
popq %r13
leaq 0x2f74(%rip), %r12      # 0x58d2
movq %r14, %rsi
xorl %eax, %eax
callq 0x10d0
movq 0x5659(%rip), %rbx      # 0x7fc8
movq (%rbx), %rdi
callq 0x1260
cmpl $0x1b, %eax
jne 0x2996
movq (%rbx), %rdi
callq 0x1260
cmpl $0x5b, %eax
jne 0x29c1
movq (%rbx), %rdi
callq 0x1260
addl $0x100, %eax            # imm = 0x100
leal -0x141(%rax), %ecx
cmpl $0x4, %ecx
jb 0x29bc
cmpl $0x4e, %eax
je 0x29c6
cmpl $0x59, %eax
je 0x29b5
cmpl $0x6e, %eax
je 0x29c6
cmpl $0x79, %eax
jne 0x29cc
xorl %ebp, %ebp
movl %r13d, %eax
jmp 0x29cc
xorl $0x1, %ebp
jmp 0x29cc
pushq $0x1b
popq %rax
jmp 0x29cc
movl %r13d, %eax
pushq $0x1
popq %rbp
testl %ebp, %ebp
movl $0x206f6e, %ecx         # imm = 0x206F6E
cmovel %r15d, %ecx
movl %ecx, 0x18(%rsp)
movq %r12, %rdi
cmpl $0xa, %eax
jne 0x295e
leaq 0x18(%rsp), %rdi
callq 0x1070
xorl %ebx, %ebx
leaq 0xc4(%rsp), %r14
xorl %edi, %edi
movq %r14, %rsi
callq 0x11a0
orb $0xa, 0xc(%r14)
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
callq 0x11b0
testl %ebp, %ebp
leaq 0x30059a9(%rip), %r14   # 0x30083c8
jne 0x2a65
leaq 0x2f9d(%rip), %rdi      # 0x59c5
callq 0x1070
movq (%r14), %rdi
leaq 0x2ea2(%rip), %rsi      # 0x58d9
movapd 0x80(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movapd 0x70(%rsp), %xmm3
movsd 0x28(%rsp), %xmm4
movsd 0x20(%rsp), %xmm5
movb $0x6, %al
callq 0x1150
movq (%r14), %rdi
callq 0x10b0
jmp 0x2aa7
xorl %ebx, %ebx
jmp 0x2aa7
movq 0x557e(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0x2b75(%rip), %rdi      # 0x55f9
pushq $0x1d
jmp 0x2a9b
movq 0x5569(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0x2b7e(%rip), %rdi      # 0x5617
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x1220
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq