// File: /workspace/github_c_makefile_star2_O3/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, 0xc(%rsp)
movl $0x30303330, 0x8(%rsp)  # imm = 0x30303330
movups 0x3115(%rip), %xmm0     # 0x549a
movups %xmm0, 0x5a(%rsp)
movaps 0x30ff(%rip), %xmm0     # 0x5490
movaps %xmm0, 0x50(%rsp)
movaps 0x30e3(%rip), %xmm0     # 0x5480
movaps %xmm0, 0x40(%rsp)
movabsq $0x5b1b00006d305b1b, %rax # imm = 0x5B1B00006D305B1B
movq %rax, 0x10(%rsp)
movl $0x6d3133, 0x18(%rsp)   # imm = 0x6D3133
movss 0x3007(%rip), %xmm0     # 0x53c8
movlps %xmm0, 0x6e34(%rip)     # 0x91fc
movw $0x176, 0x6da3(%rip)    # imm = 0x176
movlps %xmm0, 0x6ec4(%rip)     # 0x929c
movaps 0x3001(%rip), %xmm0     # 0x53e0
movups %xmm0, 0x6de2(%rip)     # 0x91c8
movups %xmm0, 0x6e7b(%rip)     # 0x9268
movabsq $0x3fc53b03e130e8f3, %rax # imm = 0x3FC53B03E130E8F3
movq %rax, 0x6dda(%rip)      # 0x91d8
movq %rax, 0x6e73(%rip)      # 0x9278
movw $0x177, 0x6e06(%rip)    # imm = 0x177
movapd 0x2fda(%rip), %xmm0     # 0x53f0
movupd %xmm0, 0x6ea2(%rip)     # 0x92c0
movabsq $0x4028000000000000, %rax # imm = 0x4028000000000000
movq %rax, 0x6ea1(%rip)      # 0x92d0
leaq 0x6ea2(%rip), %rdx      # 0x92d8
callq 0x3a64
leaq 0x3006f76(%rip), %rbx   # 0x30093b8
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x248a
subq $0x8, %rsp
leaq 0x6e5b(%rip), %rax      # 0x92b0
leaq 0x6d14(%rip), %rsi      # 0x9170
leaq 0x6dad(%rip), %rdx      # 0x9210
leaq 0x6e72(%rip), %rcx      # 0x92dc
leaq 0x6e93(%rip), %r8       # 0x9304
leaq 0x6ea8(%rip), %r9       # 0x9320
pushq %rax
callq 0x3bf4
addq $0x10, %rsp
movq (%rbx), %rdi
callq 0x10b0
leaq 0xbff(%rip), %rax       # 0x3090
leaq 0x178(%rsp), %rbx
movq %rax, -0x8(%rbx)
movq %rbx, %rdi
callq 0x1160
movl $0x0, 0x80(%rbx)
leaq 0x170(%rsp), %rsi
movl $0x2, %edi
xorl %edx, %edx
callq 0x1080
movq 0x6b2e(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
xorl %esi, %esi
callq 0x10c0
movl $0x1, %esi
movl $0xd, %edi
callq 0x1140
leaq 0xc4(%rsp), %rbx
xorl %edi, %edi
movq %rbx, %rsi
callq 0x1190
leaq 0x134(%rsp), %rsi
xorl %edi, %edi
callq 0x1190
andb $-0xb, 0xc(%rbx)
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x11a0
leaq 0x2fa0(%rip), %rdi      # 0x54bb
leaq 0x8(%rsp), %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10d0
movq 0x6a97(%rip), %r12      # 0x8fc8
leaq 0x30a0(%rip), %r13      # 0x55d8
leaq 0x389b(%rip), %rbp      # 0x5dda
xorl %r15d, %r15d
movq (%r12), %rdi
callq 0x1250
movl %eax, %r14d
cmpl $0x1b, %eax
jne 0x2587
movq (%r12), %rdi
callq 0x1250
movl $0x1b, %r14d
movl %r15d, %r12d
cmpl $0x5b, %eax
jne 0x26ba
movq 0x6a53(%rip), %rax      # 0x8fc8
movq (%rax), %rdi
callq 0x1250
movl %eax, %r14d
addl $0x100, %r14d           # imm = 0x100
cmpl $0x143, %r14d           # imm = 0x143
sete %al
cmpl $0x3, %r15d
setl %cl
andb %al, %cl
movzbl %cl, %r12d
addl %r15d, %r12d
cmpl $0x144, %r14d           # imm = 0x144
sete %al
testl %r12d, %r12d
setg %cl
andb %al, %cl
movzbl %cl, %eax
subl %eax, %r12d
cmpl $0x142, %r14d           # imm = 0x142
je 0x25f3
cmpl $0x141, %r14d           # imm = 0x141
jne 0x262a
cmpl $0x3, %r12d
ja 0x26ac
movl %r12d, %eax
leaq 0x2e91(%rip), %rcx      # 0x5470
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x4(%rsp), %edx
movl $0x3e8, %eax            # imm = 0x3E8
jmp 0x2619
cmpl $0x3, %r12d
ja 0x26b4
movl %r12d, %eax
leaq 0x2e59(%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
movl %edx, 0x4(%rsp)
xorl %r14d, %r14d
xorl %r12d, %r12d
jmp 0x26c6
leal -0x30(%r14), %eax
cmpl $0x9, %eax
ja 0x26ba
movslq %r12d, %rax
movb %r14b, 0x8(%rsp,%rax)
movq %rbx, %rdi
leaq 0x3a23(%rip), %rsi      # 0x606c
leaq 0x4(%rsp), %rdx
xorl %eax, %eax
callq 0x1180
jmp 0x26ba
movl 0x4(%rsp), %edx
addl $0xa, %edx
jmp 0x2667
movl 0x4(%rsp), %edx
addl $-0xa, %edx
movl %edx, 0x4(%rsp)
movl $0x2, %r12d
jmp 0x26a7
movl 0x4(%rsp), %edx
incl %edx
jmp 0x268a
movl 0x4(%rsp), %edx
addl $0x64, %edx
jmp 0x269d
movl 0x4(%rsp), %edx
decl %edx
movl %edx, 0x4(%rsp)
movl $0x3, %r12d
jmp 0x26a7
movl 0x4(%rsp), %edx
addl $-0x64, %edx
movl %edx, 0x4(%rsp)
movl $0x1, %r12d
xorl %r14d, %r14d
jmp 0x26c6
movl $0x141, %r14d           # imm = 0x141
jmp 0x26ba
movl $0x142, %r14d           # imm = 0x142
movl 0x4(%rsp), %edx
cmpl $0xa, %r14d
sete %r14b
testl %edx, %edx
jle 0x26e1
cmpl $0x3e9, %edx            # imm = 0x3E9
jb 0x26ee
movl $0x3e8, 0x4(%rsp)       # imm = 0x3E8
movl $0x3e8, %edx            # imm = 0x3E8
jmp 0x26ee
movl $0x1, 0x4(%rsp)
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x2edb(%rip), %rsi      # 0x55d3
xorl %eax, %eax
callq 0x11f0
testl %r15d, %r15d
jle 0x2713
movq %r13, %rdi
xorl %eax, %eax
callq 0x10d0
decl %r15d
jne 0x2704
movq %rbp, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10d0
cmpl $0x3, %r12d
jg 0x274b
movl $0x4, %r15d
subl %r12d, %r15d
cmpl $0x2, %r15d
movl $0x1, %eax
cmovll %eax, %r15d
movq %r13, %rdi
xorl %eax, %eax
callq 0x10d0
decl %r15d
jne 0x273c
movl %r12d, %r15d
testb %r14b, %r14b
movq 0x6870(%rip), %r12      # 0x8fc8
je 0x2542
leaq 0x31eb(%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 0x2e54(%rip), %rdi      # 0x55dd
xorl %eax, %eax
callq 0x10d0
leaq 0xc4(%rsp), %rbx
xorl %edi, %edi
movq %rbx, %rsi
callq 0x1190
orb $0xa, 0xc(%rbx)
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x11a0
leaq 0x69b7(%rip), %rdi      # 0x9170
callq 0x1b24
testl %eax, %eax
jne 0x307d
leaq 0x69a3(%rip), %rbx      # 0x9170
movq %rbx, %rdi
callq 0x1ec1
movl $0x2710, %edi           # imm = 0x2710
callq 0x1260
movq %rbx, %rdi
callq 0x1c35
leaq 0x3006bb4(%rip), %r14   # 0x30093a2
movzbl (%r14), %eax
movl %eax, 0x6a10(%rip)      # 0x9208
movl $0x1, 0x6a02(%rip)      # 0x9204
leaq 0x6a07(%rip), %rdi      # 0x9210
callq 0x1b24
testl %eax, %eax
jne 0x3084
leaq 0x69f3(%rip), %rbx      # 0x9210
movq %rbx, %rdi
callq 0x1ec1
movl $0x2710, %edi           # imm = 0x2710
callq 0x1260
movq %rbx, %rdi
callq 0x1c35
movzbl (%r14), %eax
movl %eax, 0x6a67(%rip)      # 0x92a8
movl $0x1, 0x6a59(%rip)      # 0x92a4
xorl %eax, %eax
movl %eax, 0x694d(%rip)      # 0x91a0
movl %eax, 0x69e7(%rip)      # 0x9240
movl $0x78, %ebp
leaq 0x690b(%rip), %r14      # 0x9170
leaq 0x3006b4c(%rip), %r13   # 0x30093b8
movq %r14, %rdi
callq 0x1f01
movq %rbx, %rdi
callq 0x1f01
cmpl $0x78, %ebp
jne 0x2886
callq 0x1a2c
movss 0x2b3e(%rip), %xmm0     # 0x53cc
callq 0x1a3d
callq 0x1a2c
movq %r14, %rdi
xorl %esi, %esi
callq 0x1f89
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1f89
decl %ebp
jne 0x286c
leaq 0x68b9(%rip), %rbx      # 0x9170
movq %rbx, %rdi
callq 0x1f41
leaq 0x694a(%rip), %r14      # 0x9210
movq %r14, %rdi
callq 0x1f01
movss 0x2af6(%rip), %xmm0     # 0x53cc
callq 0x1a3d
callq 0x1a2c
movq %rbx, %rdi
callq 0x2197
movq %r14, %rdi
xorl %esi, %esi
callq 0x1f89
movq %r14, %rdi
callq 0x1f41
movq %rbx, %rdi
callq 0x1f01
movss 0x2ac2(%rip), %xmm0     # 0x53cc
callq 0x1a3d
callq 0x1a2c
movq %r14, %rdi
callq 0x2197
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1f89
movq %r14, %rdi
callq 0x2212
movq %rbx, %rdi
callq 0x2212
movq %r14, %rdi
callq 0x1f01
movq %rbx, %rdi
callq 0x1f41
movl $0x3e8, %ebx            # imm = 0x3E8
xorl %edi, %edi
callq 0x30dd
decl %ebx
jne 0x294b
movl 0x6a1c(%rip), %eax      # 0x9378
cmpl 0x4(%rsp), %eax
jge 0x29cc
leaq 0x2cc9(%rip), %rbx      # 0x5632
xorl %ebp, %ebp
cmpl $0x1e, 0x6a0a(%rip)     # 0x937c
jl 0x2981
movss 0x2a54(%rip), %xmm0     # 0x53d0
callq 0x1a3d
movl $0x1, %edi
callq 0x30dd
movl 0x69e7(%rip), %esi      # 0x9378
imull $0x26e978d5, %esi, %eax # imm = 0x26E978D5
addl $0x10624d8, %eax        # imm = 0x10624D8
rorl $0x3, %eax
xorl %r14d, %r14d
cmpl $0x418936, %eax         # imm = 0x418936
ja 0x29c3
movl $0x1, %r14d
testl %ebp, %ebp
jne 0x29c3
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d0
movl 0x69b5(%rip), %esi      # 0x9378
movl %r14d, %ebp
cmpl 0x4(%rsp), %esi
jl 0x296b
leaq 0x30069dd(%rip), %rax   # 0x30093b0
movq (%rax), %rdi
testq %rdi, %rdi
je 0x29e0
callq 0x10b0
leaq 0x30069d9(%rip), %rdi   # 0x30093c0
leaq 0x2c5a(%rip), %rsi      # 0x5648
callq 0x11c0
movq %rax, (%r13)
movl 0x697b(%rip), %esi      # 0x9378
leaq 0x697c(%rip), %rdi      # 0x9380
leaq 0x90(%rsp), %rdx
leaq 0x100(%rsp), %rcx
callq 0x3759
movl 0x3006961(%rip), %esi   # 0x3009380
leaq 0xa8(%rsp), %rdx
leaq 0x118(%rsp), %r14
leaq 0x180694a(%rip), %rdi   # 0x1809380
movq %r14, %rcx
callq 0x3759
movl 0x6934(%rip), %esi      # 0x9378
movl 0x3006936(%rip), %edx   # 0x3009380
leaq 0x2bfa(%rip), %rdi      # 0x564b
xorl %eax, %eax
callq 0x10d0
movsd -0x8(%r14), %xmm0
movsd 0x10(%r14), %xmm1
movsd 0x29b4(%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
leaq (%rax,%rax,4), %rcx
leal (%rax,%rcx,4), %eax
leaq (%rsp,%rax), %rsi
addq $0x40, %rsi
movl %ebp, %eax
shrl %eax
movl %ebp, %ecx
andl $0x2, %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rsp,%rcx), %rdx
addq $0x10, %rdx
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r8
addq $0x10, %r8
leaq 0x2bc6(%rip), %rdi      # 0x5689
leaq 0x10(%rsp), %rbx
movq %rbx, %rcx
movq %rbx, %r9
movb $0x2, %al
callq 0x10d0
movsd -0x18(%r14), %xmm0
movsd (%r14), %xmm1
movsd 0x2940(%rip), %xmm2     # 0x5428
xorl %eax, %eax
ucomisd %xmm2, %xmm0
setae %al
leal (%rax,%rax,2), %eax
movl %eax, %r15d
orl $0x5, %r15d
ucomisd %xmm2, %xmm1
cmovbl %eax, %r15d
movl %r15d, %eax
andl $0x1, %eax
leaq (%rax,%rax,4), %rcx
leal (%rax,%rcx,4), %eax
leaq (%rsp,%rax), %rsi
addq $0x40, %rsi
movl %r15d, %eax
shrl %eax
movl %r15d, %ecx
andl $0x2, %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rsp,%rcx), %rdx
addq $0x10, %rdx
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r8
addq $0x10, %r8
leaq 0x2b99(%rip), %rdi      # 0x56de
movq %rbx, %rcx
movq %rbx, %r9
movb $0x2, %al
callq 0x10d0
orl %ebp, %r15d
movsd -0x10(%r14), %xmm0
movsd 0x8(%r14), %xmm1
xorl %eax, %eax
movsd 0x28b5(%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
leaq (%rax,%rax,4), %rcx
leal (%rax,%rcx,4), %eax
leaq (%rsp,%rax), %rsi
addq $0x40, %rsi
movl %ebp, %eax
shrl %eax
movl %ebp, %ecx
andl $0x2, %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rsp,%rcx), %rdx
addq $0x10, %rdx
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r8
addq $0x10, %r8
leaq 0x2b6d(%rip), %rdi      # 0x572d
movq %rbx, %rcx
movq %rbx, %r9
movb $0x2, %al
callq 0x10d0
orl %r15d, %ebp
movl 0x30067ae(%rip), %ecx   # 0x3009384
xorl %eax, %eax
testl %ecx, %ecx
setg %al
leal (%rax,%rax,2), %eax
movl 0x30067a1(%rip), %r10d  # 0x3009388
movl %eax, %r14d
orl $0x5, %r14d
testl %r10d, %r10d
cmovlel %eax, %r14d
testl %r14d, %r14d
je 0x2c3f
leaq 0x55(%rsp), %rsi
movl %r14d, %eax
andl $0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %rdx
addq $0x10, %rdx
movl %r14d, %eax
shrl %eax
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r9
addq $0x10, %r9
leaq 0x2b60(%rip), %rdi      # 0x578c
movq %rbx, %r8
xorl %eax, %eax
pushq %rbx
pushq %r10
callq 0x10d0
addq $0x10, %rsp
jmp 0x2c52
leaq 0x2b86(%rip), %rdi      # 0x57cc
leaq 0x40(%rsp), %rsi
xorl %eax, %eax
callq 0x10d0
orl %r14d, %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 0x2c23(%rip), %rdi      # 0x58da
movb $0x6, %al
callq 0x10d0
leaq 0x2c90(%rip), %rdi      # 0x5955
callq 0x1070
movapd 0x272e(%rip), %xmm0     # 0x5400
movapd 0x80(%rsp), %xmm3
movapd %xmm3, %xmm1
andpd %xmm0, %xmm1
movsd 0x2745(%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, %r15d
orl $0x5, %r15d
ucomisd %xmm2, %xmm0
cmovbel %eax, %r15d
movl %r15d, %eax
andl $0x1, %eax
leaq (%rax,%rax,4), %rcx
leal (%rax,%rcx,4), %eax
leaq (%rsp,%rax), %rsi
addq $0x40, %rsi
movl %r15d, %eax
shrl %eax
movl %r15d, %ecx
andl $0x2, %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rsp,%rcx), %rdx
addq $0x10, %rdx
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r8
addq $0x10, %r8
leaq 0x2ab2(%rip), %rdi      # 0x5804
leaq 0x10(%rsp), %rbx
movapd %xmm3, %xmm0
movq %rbx, %rcx
movq %rbx, %r9
movb $0x2, %al
callq 0x10d0
orl %ebp, %r15d
movsd 0x26c5(%rip), %xmm2     # 0x5438
xorl %eax, %eax
movsd 0x38(%rsp), %xmm0
ucomisd %xmm0, %xmm2
seta %al
movsd 0x26b6(%rip), %xmm1     # 0x5440
ucomisd %xmm1, %xmm0
leal (%rax,%rax,2), %r14d
movl $0x3, %r12d
cmoval %r12d, %r14d
movl %r14d, %eax
orl $0x5, %eax
movsd 0x28(%rsp), %xmm3
ucomisd %xmm3, %xmm2
cmoval %eax, %r14d
ucomisd %xmm1, %xmm3
movapd %xmm3, %xmm1
cmoval %eax, %r14d
movl %r14d, %eax
andl $0x1, %eax
leaq (%rax,%rax,4), %rcx
leal (%rax,%rcx,4), %eax
leaq (%rsp,%rax), %rsi
addq $0x40, %rsi
movl %r14d, %eax
shrl %eax
movl %r14d, %ecx
andl $0x2, %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rsp,%rcx), %rdx
addq $0x10, %rdx
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r8
addq $0x10, %r8
leaq 0x2a47(%rip), %rdi      # 0x5845
movq %rbx, %rcx
movq %rbx, %r9
movb $0x2, %al
callq 0x10d0
orl %r15d, %r14d
movsd 0x2632(%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 %r12d, %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
leaq (%rax,%rax,4), %rcx
leal (%rax,%rcx,4), %eax
leaq (%rsp,%rax), %rsi
addq $0x40, %rsi
movl %ebp, %eax
shrl %eax
movl %ebp, %ecx
andl $0x2, %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rsp,%rcx), %rdx
addq $0x10, %rdx
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r8
addq $0x10, %r8
leaq 0x29ef(%rip), %rdi      # 0x587f
movq %rbx, %rcx
movq %rbx, %r9
movb $0x2, %al
callq 0x10d0
orl %r14d, %ebp
andl $0x1, %ebp
sete %r12b
leaq 0x2ac9(%rip), %rax      # 0x5977
leaq 0x2ada(%rip), %rdi      # 0x598f
cmoveq %rax, %rdi
callq 0x1070
cmpq $0x0, (%r13)
je 0x2fb9
leaq 0xc4(%rsp), %rbx
xorl %edi, %edi
movq %rbx, %rsi
callq 0x1190
andb $-0xb, 0xc(%rbx)
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x11a0
leaq 0x29c3(%rip), %rdi      # 0x58b5
movl $0x736579, %ecx         # imm = 0x736579
leaq 0x8(%rsp), %rbx
leaq 0x29cf(%rip), %r14      # 0x58d2
testb $0x1, %r12b
movl $0x206f6e, %eax         # imm = 0x206F6E
cmovnel %ecx, %eax
movl %eax, 0x8(%rsp)
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10d0
testl %ebp, %ebp
sete %r12b
movl $0x736579, %eax         # imm = 0x736579
movl $0x206f6e, %r13d        # imm = 0x206F6E
cmovel %eax, %r13d
movq 0x608f(%rip), %r15      # 0x8fc8
movq (%r15), %rdi
callq 0x1250
cmpl $0x1b, %eax
jne 0x2f60
movq (%r15), %rdi
callq 0x1250
cmpl $0x5b, %eax
jne 0x2fa6
movq (%r15), %rdi
callq 0x1250
addl $0x100, %eax            # imm = 0x100
cmpl $0x78, %eax
jg 0x2f76
cmpl $0x4e, %eax
je 0x2fc0
cmpl $0x59, %eax
je 0x2fca
cmpl $0x6e, %eax
jne 0x2f86
jmp 0x2fc0
leal -0x141(%rax), %ecx
cmpl $0x4, %ecx
jb 0x2fa3
cmpl $0x79, %eax
je 0x2fca
movl %r13d, 0x8(%rsp)
cmpl $0xa, %eax
je 0x3071
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10d0
jmp 0x2f32
xorl $0x1, %ebp
testl %ebp, %ebp
sete %r12b
movq %r14, %rdi
movl $0x736579, %ecx         # imm = 0x736579
jmp 0x2f03
xorl %ebx, %ebx
jmp 0x305d
movl $0x206f6e, %eax         # imm = 0x206F6E
xorl %r12d, %r12d
jmp 0x2fd2
movl $0x736579, %eax         # imm = 0x736579
movb $0x1, %r12b
leaq 0x30063df(%rip), %r15   # 0x30093b8
movl %eax, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x1070
xorl %ebx, %ebx
leaq 0xc4(%rsp), %r14
xorl %edi, %edi
movq %r14, %rsi
callq 0x1190
orb $0xa, 0xc(%r14)
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
callq 0x11a0
testb %r12b, %r12b
je 0x3055
leaq 0x29ad(%rip), %rdi      # 0x59c5
callq 0x1070
movq (%r15), %rdi
leaq 0x28b2(%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 (%r15), %rdi
callq 0x10b0
movl %ebx, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3006340(%rip), %r15   # 0x30093b8
jmp 0x2fdd
callq 0x152b
jmp 0x3089
callq 0x154d
movl $0x1, %ebx
jmp 0x305d