// File: /workspace/github_c_makefile_star2_O1/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 0x30d1(%rip), %xmm0     # 0x547a
movups %xmm0, 0x5a(%rsp)
movaps 0x30bb(%rip), %xmm0     # 0x5470
movaps %xmm0, 0x50(%rsp)
movapd 0x309e(%rip), %xmm0     # 0x5460
movapd %xmm0, 0x40(%rsp)
movabsq $0x5b1b00006d305b1b, %rax # imm = 0x5B1B00006D305B1B
movq %rax, 0x8(%rsp)
movl $0x6d3133, 0x10(%rsp)   # imm = 0x6D3133
xorl %eax, %eax
movl %eax, 0x6e19(%rip)      # 0x9200
movl $0x3f800000, %ecx       # imm = 0x3F800000
movl %ecx, 0x6e0a(%rip)      # 0x91fc
movw $0x176, 0x6d79(%rip)    # imm = 0x176
movl %eax, 0x6e9f(%rip)      # 0x92a0
movl %ecx, 0x6e95(%rip)      # 0x929c
movabsq $-0x4160dffa0734d60a, %rax # imm = 0xBE9F2005F8CB29F6
movq %rax, 0x6db0(%rip)      # 0x91c8
movq %rax, 0x6e49(%rip)      # 0x9268
movabsq $0x3fee72235e0bcb7c, %rax # imm = 0x3FEE72235E0BCB7C
movq %rax, 0x6da0(%rip)      # 0x91d0
movq %rax, 0x6e39(%rip)      # 0x9270
movabsq $0x3fc53b03e130e8f3, %rax # imm = 0x3FC53B03E130E8F3
movq %rax, 0x6d90(%rip)      # 0x91d8
movq %rax, 0x6e29(%rip)      # 0x9278
movw $0x177, 0x6dbc(%rip)    # imm = 0x177
movabsq $0x3fb111111109bc91, %rax # imm = 0x3FB111111109BC91
movq %rax, 0x6e57(%rip)      # 0x92c0
movabsq $0x4049000000000000, %rax # imm = 0x4049000000000000
movq %rax, 0x6e4e(%rip)      # 0x92c8
movabsq $0x4028000000000000, %rax # imm = 0x4028000000000000
movq %rax, 0x6e45(%rip)      # 0x92d0
leaq 0x6e46(%rip), %rdx      # 0x92d8
callq 0x3a24
leaq 0x3006f1a(%rip), %rbx   # 0x30093b8
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x24e6
subq $0x8, %rsp
leaq 0x6dff(%rip), %rax      # 0x92b0
leaq 0x6cb8(%rip), %rsi      # 0x9170
leaq 0x6d51(%rip), %rdx      # 0x9210
leaq 0x6e16(%rip), %rcx      # 0x92dc
leaq 0x6e37(%rip), %r8       # 0x9304
leaq 0x6e4c(%rip), %r9       # 0x9320
pushq %rax
callq 0x3bb4
addq $0x10, %rsp
movq (%rbx), %rdi
callq 0x10b0
leaq 0xb79(%rip), %rax       # 0x3066
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 0x6ad2(%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 0x2f24(%rip), %rdi      # 0x549b
leaq 0x18(%rsp), %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10d0
movq 0x6a3b(%rip), %r12      # 0x8fc8
leaq 0x3024(%rip), %r13      # 0x55b8
leaq 0x381f(%rip), %rbp      # 0x5dba
xorl %r15d, %r15d
movq (%r12), %rdi
callq 0x1250
movl %eax, %r14d
cmpl $0x1b, %eax
jne 0x25d6
movq (%r12), %rdi
callq 0x1250
movl $0x1b, %r14d
cmpl $0x5b, %eax
jne 0x25d6
movq (%r12), %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 0x2658
cmpl $0x141, %r14d           # imm = 0x141
jne 0x268d
cmpl $0x3, %r12d
ja 0x264f
movl %r12d, %eax
leaq 0x2e16(%rip), %rcx      # 0x5440
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addl $0x3e8, 0x4(%rsp)       # imm = 0x3E8
jmp 0x264f
addl $0xa, 0x4(%rsp)
jmp 0x264f
incl 0x4(%rsp)
jmp 0x264f
addl $0x64, 0x4(%rsp)
cmpl $0x142, %r14d           # imm = 0x142
jne 0x268d
cmpl $0x3, %r12d
ja 0x268d
movl %r12d, %eax
leaq 0x2de8(%rip), %rcx      # 0x5450
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addl $0xfffffc18, 0x4(%rsp)  # imm = 0xFFFFFC18
jmp 0x268d
addl $-0xa, 0x4(%rsp)
jmp 0x268d
decl 0x4(%rsp)
jmp 0x268d
addl $-0x64, 0x4(%rsp)
leal -0x30(%r14), %eax
cmpl $0x9, %eax
ja 0x26b4
movslq %r12d, %rax
movb %r14b, 0x18(%rsp,%rax)
movq %rbx, %rdi
leaq 0x39a8(%rip), %rsi      # 0x6050
leaq 0x4(%rsp), %rdx
xorl %eax, %eax
callq 0x1180
cmpl $0x0, 0x4(%rsp)
jg 0x26c3
movl $0x1, 0x4(%rsp)
cmpl $0x3e9, 0x4(%rsp)       # imm = 0x3E9
jl 0x26d5
movl $0x3e8, 0x4(%rsp)       # imm = 0x3E8
movl 0x4(%rsp), %edx
movq %rbx, %rdi
leaq 0x2ed0(%rip), %rsi      # 0x55b3
xorl %eax, %eax
callq 0x11f0
testl %r15d, %r15d
jle 0x26fe
movq %r13, %rdi
xorl %eax, %eax
callq 0x10d0
decl %r15d
jne 0x26ef
movq %rbp, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10d0
cmpl $0x3, %r12d
jg 0x2739
movl $0x4, %r15d
subl %r12d, %r15d
cmpl $0x2, %r15d
movl $0x1, %eax
cmovll %eax, %r15d
negl %r15d
movq %r13, %rdi
xorl %eax, %eax
callq 0x10d0
incl %r15d
jne 0x272a
movl %r12d, %r15d
cmpl $0xa, %r14d
movq 0x6881(%rip), %r12      # 0x8fc8
jne 0x259e
leaq 0x31dc(%rip), %rdi      # 0x5930
callq 0x1070
cmpl $0x3e9, 0x4(%rsp)       # imm = 0x3E9
jl 0x276b
movl $0x3e8, 0x4(%rsp)       # imm = 0x3E8
imull $0x3e8, 0x4(%rsp), %esi # imm = 0x3E8
movl %esi, 0x4(%rsp)
leaq 0x2e3f(%rip), %rdi      # 0x55bd
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 0x69c2(%rip), %rdi      # 0x9170
callq 0x1b84
testl %eax, %eax
leaq 0x3006bfc(%rip), %r13   # 0x30093b8
jne 0x3041
leaq 0x69a7(%rip), %rbx      # 0x9170
movq %rbx, %rdi
callq 0x1f06
movl $0x2710, %edi           # imm = 0x2710
callq 0x1260
movq %rbx, %rdi
callq 0x1c95
leaq 0x3006bb8(%rip), %r14   # 0x30093a2
movzbl (%r14), %eax
movl %eax, 0x6a14(%rip)      # 0x9208
movl $0x1, 0x6a06(%rip)      # 0x9204
leaq 0x6a0b(%rip), %rdi      # 0x9210
callq 0x1b84
testl %eax, %eax
jne 0x3048
leaq 0x69f7(%rip), %rbx      # 0x9210
movq %rbx, %rdi
callq 0x1f06
movl $0x2710, %edi           # imm = 0x2710
callq 0x1260
movq %rbx, %rdi
callq 0x1c95
movzbl (%r14), %eax
movl %eax, 0x6a6b(%rip)      # 0x92a8
movl $0x1, 0x6a5d(%rip)      # 0x92a4
xorl %eax, %eax
movl %eax, 0x6951(%rip)      # 0x91a0
movl %eax, 0x69eb(%rip)      # 0x9240
movl $0x78, %ebp
leaq 0x690f(%rip), %r14      # 0x9170
movq %r14, %rdi
callq 0x1f47
movq %rbx, %rdi
callq 0x1f47
cmpl $0x78, %ebp
jne 0x287b
callq 0x1a8c
movss 0x2b45(%rip), %xmm0     # 0x53c8
callq 0x1a9d
callq 0x1a8c
movq %r14, %rdi
xorl %esi, %esi
callq 0x1fcf
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1fcf
decl %ebp
jne 0x2861
leaq 0x68c4(%rip), %rbx      # 0x9170
movq %rbx, %rdi
callq 0x1f88
leaq 0x6955(%rip), %r14      # 0x9210
movq %r14, %rdi
callq 0x1f47
movss 0x2afd(%rip), %xmm0     # 0x53c8
callq 0x1a9d
callq 0x1a8c
movq %rbx, %rdi
callq 0x21b9
movq %r14, %rdi
xorl %esi, %esi
callq 0x1fcf
movq %r14, %rdi
callq 0x1f88
movq %rbx, %rdi
callq 0x1f47
movss 0x2ac9(%rip), %xmm0     # 0x53c8
callq 0x1a9d
callq 0x1a8c
movq %r14, %rdi
callq 0x21b9
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1fcf
movq %r14, %rdi
callq 0x2234
movq %rbx, %rdi
callq 0x2234
movq %r14, %rdi
callq 0x1f47
movq %rbx, %rdi
callq 0x1f88
movl $0x3e8, %ebx            # imm = 0x3E8
xorl %edi, %edi
callq 0x30b3
decl %ebx
jne 0x2940
movl 0x6a27(%rip), %eax      # 0x9378
cmpl 0x4(%rsp), %eax
jge 0x29c1
leaq 0x2cb4(%rip), %rbx      # 0x5612
xorl %ebp, %ebp
cmpl $0x1e, 0x6a15(%rip)     # 0x937c
jl 0x2976
movss 0x2a5b(%rip), %xmm0     # 0x53cc
callq 0x1a9d
movl $0x1, %edi
callq 0x30b3
movl 0x69f2(%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 0x29b2
movl $0x1, %r14d
testl %ebp, %ebp
jne 0x29b2
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10d0
movl 0x69c0(%rip), %eax      # 0x9378
movl %r14d, %ebp
cmpl 0x4(%rsp), %eax
jl 0x2960
leaq 0x30069e8(%rip), %rax   # 0x30093b0
movq (%rax), %rdi
testq %rdi, %rdi
je 0x29d5
callq 0x10b0
leaq 0x30069e4(%rip), %rdi   # 0x30093c0
leaq 0x2c45(%rip), %rsi      # 0x5628
callq 0x11c0
movq %rax, (%r13)
movl 0x6986(%rip), %esi      # 0x9378
leaq 0x6987(%rip), %rdi      # 0x9380
leaq 0x90(%rsp), %rdx
leaq 0x100(%rsp), %rcx
callq 0x370b
movl 0x300696c(%rip), %esi   # 0x3009380
leaq 0xa8(%rsp), %rdx
leaq 0x118(%rsp), %r14
leaq 0x1806955(%rip), %rdi   # 0x1809380
movq %r14, %rcx
callq 0x370b
movl 0x693f(%rip), %esi      # 0x9378
movl 0x3006941(%rip), %edx   # 0x3009380
leaq 0x2be5(%rip), %rdi      # 0x562b
xorl %eax, %eax
callq 0x10d0
movsd -0x8(%r14), %xmm0
movsd 0x10(%r14), %xmm1
movsd 0x2977(%rip), %xmm2     # 0x53d8
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 $0x8, %rdx
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r8
addq $0x8, %r8
leaq 0x2bb1(%rip), %rdi      # 0x5669
leaq 0x8(%rsp), %rbx
movq %rbx, %rcx
movq %rbx, %r9
movb $0x2, %al
callq 0x10d0
movsd -0x18(%r14), %xmm0
movsd (%r14), %xmm1
movsd 0x2903(%rip), %xmm2     # 0x53e0
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 $0x8, %rdx
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r8
addq $0x8, %r8
leaq 0x2b84(%rip), %rdi      # 0x56be
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 0x2878(%rip), %xmm2     # 0x53d8
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 $0x8, %rdx
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r8
addq $0x8, %r8
leaq 0x2b58(%rip), %rdi      # 0x570d
movq %rbx, %rcx
movq %rbx, %r9
movb $0x2, %al
callq 0x10d0
orl %r15d, %ebp
movl 0x30067b9(%rip), %ecx   # 0x3009384
xorl %eax, %eax
testl %ecx, %ecx
setg %al
leal (%rax,%rax,2), %eax
movl 0x30067ac(%rip), %r10d  # 0x3009388
movl %eax, %r14d
orl $0x5, %r14d
testl %r10d, %r10d
cmovlel %eax, %r14d
testl %r14d, %r14d
je 0x2c34
leaq 0x55(%rsp), %rsi
movl %r14d, %eax
andl $0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %rdx
addq $0x8, %rdx
movl %r14d, %eax
shrl %eax
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r9
addq $0x8, %r9
leaq 0x2b4b(%rip), %rdi      # 0x576c
movq %rbx, %r8
xorl %eax, %eax
pushq %rbx
pushq %r10
callq 0x10d0
addq $0x10, %rsp
jmp 0x2c47
leaq 0x2b71(%rip), %rdi      # 0x57ac
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 0x2c0e(%rip), %rdi      # 0x58ba
movb $0x6, %al
callq 0x10d0
leaq 0x2c7b(%rip), %rdi      # 0x5935
callq 0x1070
movapd 0x2759(%rip), %xmm0     # 0x5420
movapd 0x80(%rsp), %xmm3
movapd %xmm3, %xmm1
andpd %xmm0, %xmm1
movsd 0x2708(%rip), %xmm2     # 0x53e8
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 $0x8, %rdx
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r8
addq $0x8, %r8
leaq 0x2a9d(%rip), %rdi      # 0x57e4
leaq 0x8(%rsp), %rbx
movapd %xmm3, %xmm0
movq %rbx, %rcx
movq %rbx, %r9
movb $0x2, %al
callq 0x10d0
orl %ebp, %r15d
movsd 0x2688(%rip), %xmm2     # 0x53f0
xorl %eax, %eax
movsd 0x38(%rsp), %xmm0
ucomisd %xmm0, %xmm2
seta %al
movsd 0x2679(%rip), %xmm1     # 0x53f8
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 $0x8, %rdx
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r8
addq $0x8, %r8
leaq 0x2a32(%rip), %rdi      # 0x5825
movq %rbx, %rcx
movq %rbx, %r9
movb $0x2, %al
callq 0x10d0
orl %r15d, %r14d
movsd 0x25f5(%rip), %xmm2     # 0x5400
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 $0x8, %rdx
andl $-0x2, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax), %r8
addq $0x8, %r8
leaq 0x29da(%rip), %rdi      # 0x585f
movq %rbx, %rcx
movq %rbx, %r9
movb $0x2, %al
callq 0x10d0
orl %r14d, %ebp
andl $0x1, %ebp
leaq 0x2ab8(%rip), %rax      # 0x5957
leaq 0x2ac9(%rip), %rdi      # 0x596f
cmoveq %rax, %rdi
callq 0x1070
cmpq $0x0, (%r13)
je 0x303d
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
testl %ebp, %ebp
movl $0x736579, %r12d        # imm = 0x736579
movl $0x206f6e, %eax         # imm = 0x206F6E
cmovel %r12d, %eax
leaq 0x18(%rsp), %rbx
movl %eax, (%rbx)
leaq 0x299a(%rip), %rdi      # 0x5895
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10d0
leaq 0x29a6(%rip), %r14      # 0x58b2
movq 0x60b5(%rip), %r13      # 0x8fc8
movq (%r13), %rdi
callq 0x1250
movl %eax, %r15d
cmpl $0x1b, %eax
jne 0x2f4b
movq (%r13), %rdi
callq 0x1250
movl $0x1b, %r15d
cmpl $0x5b, %eax
jne 0x2f4b
movq (%r13), %rdi
callq 0x1250
movl %eax, %r15d
addl $0x100, %r15d           # imm = 0x100
cmpl $0x78, %r15d
jg 0x2f6a
cmpl $0x4e, %r15d
je 0x2f63
cmpl $0x59, %r15d
je 0x2f81
cmpl $0x6e, %r15d
jne 0x2f89
movl $0x1, %ebp
jmp 0x2f83
leal -0x141(%r15), %eax
cmpl $0x4, %eax
jae 0x2f7b
xorl $0x1, %ebp
jmp 0x2f89
cmpl $0x79, %r15d
jne 0x2f89
xorl %ebp, %ebp
movl $0xa, %r15d
testl %ebp, %ebp
movl $0x206f6e, %eax         # imm = 0x206F6E
cmovel %r12d, %eax
movl %eax, 0x18(%rsp)
cmpl $0xa, %r15d
jne 0x2fa8
movq %rbx, %rdi
callq 0x1070
jmp 0x2fb5
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10d0
cmpl $0xa, %r15d
jne 0x2f0c
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
testl %ebp, %ebp
leaq 0x30063cb(%rip), %r14   # 0x30093b8
jne 0x3033
leaq 0x29af(%rip), %rdi      # 0x59a5
callq 0x1070
movq (%r14), %rdi
leaq 0x28b4(%rip), %rsi      # 0x58b9
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 0x3052
xorl %ebx, %ebx
jmp 0x3052
callq 0x1599
jmp 0x304d
callq 0x15bb
movl $0x1, %ebx
movl %ebx, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq