// File: /workspace/github_c_makefile_star2_O3/Openvario[P]sensord/compdata.c
// Function: pressure_measurement_handler
static void pressure_measurement_handler(int record)
{
	static unsigned int meas_counter=1, glitchstart=0,shutdown=0,deltaxmax=0;
	int x=0, deltax;
	double comp;

	// if early, wait
	// if more than 2ms late, increase the glitch counter
	if ((sensor_wait(12500))>2000) { glitchstart=8; glitch+=8; }
	if (meas_counter&1) {
		// read pressure sensors
		x|=ms5611_read_temp(&tep_sensor,glitch);
		x|=ms5611_read_pressure(&static_sensor);
		x|=ms5611_start_pressure(&tep_sensor);
		sensor_wait_mark();
		x|=ms5611_start_temp(&static_sensor);

		if (abs((int)static_sensor.D1l-(int) static_sensor.D1)<100e3) {
			if (glitch==0) {
				shutdown=0;
				if (tep_sensor.D2l>tep_sensor.D2+300) { glitchstart=8; glitch=8; }
			}
			if (glitchstart) {
				if (glitch>glitchstart)
					deltax=abs((int)tep_sensor.D2l-(int)tep_sensor.D2);
				else
					deltax=abs((int)tep_sensor.D2f-(int)tep_sensor.D2);
				if (deltax>deltaxmax) deltaxmax=deltax;
				if ((--glitchstart)==0) {
					if (deltaxmax>15)
						glitch += ((int) round(log((double)(deltaxmax)*config.timing_log)*config.timing_mult))+config.timing_off;
					deltaxmax=0;
				}
			}
			if (glitch>0) {
				if (--glitch>399) glitch=399;
				if (!glitch) ++urun;
				if (++shutdown==800) {
					glitch=shutdown=0;
					++orun;
				}
				if (tep_sensor.D2>(int)round(tep_sensor.D2f-15)) glitch=0;
				if (glitch && record && ((int)round(tep_sensor.D2f)>tep_sensor.D2+500)) {
					comp=static_sensor.p*1e-5;
					comp=comp*comp*static_sensor.Pcomp2+comp*static_sensor.Pcomp1+static_sensor.Pcomp0;
					statval[sidx][0]=((double)static_sensor.D1f-(double)static_sensor.D1)/comp;
					statval[sidx][1]=((double)tep_sensor.D2f-(double)tep_sensor.D2);
					statval[sidx++][2]=x;
				}
			} else {
				static_sensor.D1f=(static_sensor.D1f*7+static_sensor.D1)>>3;
				ms5611_calculate_pressure(&static_sensor);
			}
		}
	} else {
		// read pressure sensors
		x|=ms5611_read_pressure(&tep_sensor);
		x|=ms5611_read_temp(&static_sensor,glitch);
		x|=ms5611_start_temp(&tep_sensor);
		sensor_wait_mark();
		x|=ms5611_start_pressure(&static_sensor);

		if (abs((int)tep_sensor.D1l-(int) tep_sensor.D1)<100e3) {
			if (glitch==0) {
				shutdown=0;
				if (static_sensor.D2l>static_sensor.D2+300) { glitchstart=8; glitch=8; }
			}
			if (glitchstart) {
				if (glitch>glitchstart)
					deltax=abs((int)static_sensor.D2l-(int)static_sensor.D2);
				else
					deltax=abs((int)static_sensor.D2f-(int)static_sensor.D2);
				if (deltax>deltaxmax) deltaxmax=deltax;
				if ((--glitchstart)==0) {
					if (deltaxmax>15)
						glitch += ((int) round(log((double)(deltaxmax)*config.timing_log)*config.timing_mult))+config.timing_off;
					deltaxmax=0;
				}
			}
			if (glitch>0) {
				if (--glitch>399) glitch=399;
				if (!glitch) ++urun;
				if (++shutdown==800) {
					glitch=shutdown=0;
					++orun;
				}
				if (static_sensor.D2>(int)round(static_sensor.D2f-15)) glitch=0;
				if (glitch && record && ((int)round(static_sensor.D2f)>static_sensor.D2+500)) {
					comp=tep_sensor.p*1e-5;
					comp=comp*comp*tep_sensor.Pcomp2+comp*tep_sensor.Pcomp1+tep_sensor.Pcomp0;
					tepval[tidx][0]=((double)tep_sensor.D1f-(double)tep_sensor.D1)/comp;
					tepval[tidx][1]=((double)static_sensor.D2f-(double)static_sensor.D2);
					tepval[tidx++][2]=x;

				}
			} else {
				tep_sensor.D1f=(tep_sensor.D1f*7+tep_sensor.D1)>>3;
				ms5611_calculate_pressure(&tep_sensor);
			}
		}
	}
	if (glitch) noglitch=0; else noglitch++;
	meas_counter++;
	if (io_mode.sensordata_to_file) {
		if ((meas_counter%2==1) && (record))
			fprintf(fp_datalog, "%.4f %.4f %f %u %u %u %u %u %u %u %u %d\n",tep_sensor.p,static_sensor.p,dynamic_sensor.p,static_sensor.D1,static_sensor.D1f,tep_sensor.D1,tep_sensor.D1f,static_sensor.D2,static_sensor.D2f,tep_sensor.D2,tep_sensor.D2f,glitch);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
movss 0x22da(%rip), %xmm0     # 0x53cc
callq 0x1a3d
ucomiss 0x22d6(%rip), %xmm0     # 0x53d4
jbe 0x3111
movl $0x8, 0x3006282(%rip)   # 0x300938c
addl $0x8, 0x3006287(%rip)   # 0x3009398
testb $0x1, 0x6030(%rip)      # 0x9148
jne 0x31d0
leaq 0x60eb(%rip), %r15      # 0x9210
movq %r15, %rdi
callq 0x2197
movl %eax, %r14d
movl 0x3006262(%rip), %esi   # 0x3009398
leaq 0x6033(%rip), %r13      # 0x9170
movq %r13, %rdi
callq 0x1f89
movl %eax, %ebp
movq %r15, %rdi
callq 0x1f01
movl %eax, %r15d
callq 0x1a2c
movq %r13, %rdi
callq 0x1f41
movl %eax, %r12d
movl 0x60cc(%rip), %eax      # 0x9234
subl 0x60be(%rip), %eax      # 0x922c
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0x1869f, %ecx          # imm = 0x1869F
ja 0x3680
movl 0x3006211(%rip), %eax   # 0x3009398
testl %eax, %eax
jne 0x3282
movl $0x0, 0x30061f7(%rip)   # 0x3009390
movl $0x12c, %ecx            # imm = 0x12C
addl 0x5ff4(%rip), %ecx      # 0x9198
cmpl %ecx, 0x5ff2(%rip)      # 0x919c
jbe 0x3282
movl $0x8, 0x30061de(%rip)   # 0x3009398
movl $0x8, %eax
movl $0x7, %ecx
leaq 0x5fd5(%rip), %rdx      # 0x91a0
jmp 0x32a4
movl 0x30061c2(%rip), %esi   # 0x3009398
leaq 0x6033(%rip), %r13      # 0x9210
movq %r13, %rdi
callq 0x1f89
movl %eax, %r14d
leaq 0x5f81(%rip), %r12      # 0x9170
movq %r12, %rdi
callq 0x2197
movl %eax, %ebp
movq %r13, %rdi
callq 0x1f41
movl %eax, %r15d
callq 0x1a2c
movq %r12, %rdi
callq 0x1f01
movl %eax, %r12d
movl 0x5f7a(%rip), %eax      # 0x9194
subl 0x5f6c(%rip), %eax      # 0x918c
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0x1869f, %ecx          # imm = 0x1869F
ja 0x3680
movl 0x300615f(%rip), %eax   # 0x3009398
testl %eax, %eax
jne 0x3450
movl $0x0, 0x3006145(%rip)   # 0x3009390
movl $0x12c, %ecx            # imm = 0x12C
addl 0x5fe2(%rip), %ecx      # 0x9238
cmpl %ecx, 0x5fe0(%rip)      # 0x923c
jbe 0x3450
movl $0x8, 0x300612c(%rip)   # 0x3009398
movl $0x8, %eax
movl $0x7, %ecx
leaq 0x5fc3(%rip), %rdx      # 0x9240
jmp 0x3472
movl 0x3006104(%rip), %ecx   # 0x300938c
testl %ecx, %ecx
je 0x3325
xorl %edx, %edx
cmpl %ecx, %eax
setbe %dl
leaq 0x2c(,%rdx,4), %rdx
addq %r13, %rdx
decl %ecx
movl (%rdx), %edx
subl 0x5eec(%rip), %edx      # 0x9198
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
movl 0x30060db(%rip), %edx   # 0x3009394
cmpl %edx, %esi
jbe 0x32c5
movl %esi, 0x30060d1(%rip)   # 0x3009394
movl %esi, %edx
movl %ecx, 0x30060c1(%rip)   # 0x300938c
testl %ecx, %ecx
jne 0x3325
cmpl $0x10, %edx
jb 0x331b
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
mulsd 0x5fdd(%rip), %xmm0     # 0x92c0
callq 0x1110
mulsd 0x5fd8(%rip), %xmm0     # 0x92c8
callq 0x1050
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
addsd 0x5fcb(%rip), %xmm0     # 0x92d0
cvtsi2sdl 0x300608b(%rip), %xmm1 # 0x3009398
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, 0x300607d(%rip)   # 0x3009398
movl $0x0, 0x300606f(%rip)   # 0x3009394
testl %eax, %eax
jle 0x3560
movl $0x190, %edx            # imm = 0x190
cmpl %edx, %eax
cmovbl %eax, %edx
decl %edx
movl %edx, 0x3006059(%rip)   # 0x3009398
jne 0x3347
incl 0x300603d(%rip)         # 0x3009384
movl 0x3006043(%rip), %eax   # 0x3009390
incl %eax
movl %eax, 0x300603b(%rip)   # 0x3009390
cmpl $0x320, %eax            # imm = 0x320
jne 0x3370
xorl %edx, %edx
movl %edx, 0x300602c(%rip)   # 0x3009390
movl %edx, 0x300602e(%rip)   # 0x3009398
incl 0x3006018(%rip)         # 0x3009388
movl 0x5e22(%rip), %eax      # 0x9198
movl 0x5e24(%rip), %ecx      # 0x91a0
leal -0xf(%rcx), %esi
cmpl %esi, %eax
ja 0x3551
leal 0x1f4(%rax), %esi
cmpl %esi, %ecx
jbe 0x3680
testl %ebx, %ebx
je 0x3680
testl %edx, %edx
je 0x3680
xorps %xmm0, %xmm0
cvtss2sd 0x5ee8(%rip), %xmm0     # 0x9298
mulsd 0x2098(%rip), %xmm0     # 0x5450
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd 0x5ea8(%rip), %xmm0     # 0x9270
mulsd 0x5e98(%rip), %xmm1     # 0x9268
addsd %xmm0, %xmm1
addsd 0x5e9c(%rip), %xmm1     # 0x9278
orl %r15d, %r14d
movl 0x5e4b(%rip), %edx      # 0x9230
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
orl %r12d, %r14d
movl 0x5e36(%rip), %edx      # 0x922c
cvtsi2sd %rdx, %xmm2
orl %r14d, %ebp
subsd %xmm2, %xmm0
divsd %xmm1, %xmm0
movslq 0x3005f73(%rip), %rdx   # 0x3009380
leaq (%rdx,%rdx,2), %rsi
movl %ecx, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
leaq 0x1805f5e(%rip), %rcx   # 0x1809380
movl %eax, %eax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
movsd %xmm0, (%rcx,%rsi,8)
subsd %xmm2, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm1, 0x8(%rcx,%rsi,8)
leal 0x1(%rdx), %eax
movl %eax, 0x3005f35(%rip)   # 0x3009380
jmp 0x367a
movl 0x3005f36(%rip), %ecx   # 0x300938c
testl %ecx, %ecx
je 0x34f3
xorl %edx, %edx
cmpl %ecx, %eax
setbe %dl
leaq 0x2c(,%rdx,4), %rdx
addq %r13, %rdx
decl %ecx
movl (%rdx), %edx
subl 0x5dbe(%rip), %edx      # 0x9238
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
movl 0x3005f0d(%rip), %edx   # 0x3009394
cmpl %edx, %esi
jbe 0x3493
movl %esi, 0x3005f03(%rip)   # 0x3009394
movl %esi, %edx
movl %ecx, 0x3005ef3(%rip)   # 0x300938c
testl %ecx, %ecx
jne 0x34f3
cmpl $0x10, %edx
jb 0x34e9
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
mulsd 0x5e0f(%rip), %xmm0     # 0x92c0
callq 0x1110
mulsd 0x5e0a(%rip), %xmm0     # 0x92c8
callq 0x1050
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
addsd 0x5dfd(%rip), %xmm0     # 0x92d0
cvtsi2sdl 0x3005ebd(%rip), %xmm1 # 0x3009398
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, 0x3005eaf(%rip)   # 0x3009398
movl $0x0, 0x3005ea1(%rip)   # 0x3009394
testl %eax, %eax
jle 0x3587
movl $0x190, %edx            # imm = 0x190
cmpl %edx, %eax
cmovbl %eax, %edx
decl %edx
movl %edx, 0x3005e8b(%rip)   # 0x3009398
jne 0x3515
incl 0x3005e6f(%rip)         # 0x3009384
movl 0x3005e75(%rip), %eax   # 0x3009390
incl %eax
movl %eax, 0x3005e6d(%rip)   # 0x3009390
cmpl $0x320, %eax            # imm = 0x320
jne 0x353e
xorl %edx, %edx
movl %edx, 0x3005e5e(%rip)   # 0x3009390
movl %edx, 0x3005e60(%rip)   # 0x3009398
incl 0x3005e4a(%rip)         # 0x3009388
movl 0x5cf4(%rip), %eax      # 0x9238
movl 0x5cf6(%rip), %ecx      # 0x9240
leal -0xf(%rcx), %esi
cmpl %esi, %eax
jbe 0x35b6
movl $0x0, 0x3005e3d(%rip)   # 0x3009398
jmp 0x3680
leaq 0x5ca9(%rip), %rdi      # 0x9210
movl 0x5cc3(%rip), %eax      # 0x9230
leal (,%rax,8), %ecx
subl %eax, %ecx
addl 0x5cb0(%rip), %ecx      # 0x922c
shrl $0x3, %ecx
movl %ecx, 0x5cab(%rip)      # 0x9230
jmp 0x35ac
leaq 0x5be2(%rip), %rdi      # 0x9170
movl 0x5bfc(%rip), %eax      # 0x9190
leal (,%rax,8), %ecx
subl %eax, %ecx
addl 0x5be9(%rip), %ecx      # 0x918c
shrl $0x3, %ecx
movl %ecx, 0x5be4(%rip)      # 0x9190
callq 0x2212
jmp 0x3680
leal 0x1f4(%rax), %esi
cmpl %esi, %ecx
jbe 0x3680
testl %ebx, %ebx
je 0x3680
testl %edx, %edx
je 0x3680
xorps %xmm0, %xmm0
cvtss2sd 0x5c19(%rip), %xmm0     # 0x91f8
mulsd 0x1e69(%rip), %xmm0     # 0x5450
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd 0x5bd9(%rip), %xmm0     # 0x91d0
mulsd 0x5bc9(%rip), %xmm1     # 0x91c8
addsd %xmm0, %xmm1
addsd 0x5bcd(%rip), %xmm1     # 0x91d8
orl %r15d, %ebp
movl 0x5b7c(%rip), %edx      # 0x9190
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
orl %r12d, %ebp
movl 0x5b67(%rip), %edx      # 0x918c
cvtsi2sd %rdx, %xmm2
orl %r14d, %ebp
subsd %xmm2, %xmm0
divsd %xmm1, %xmm0
movslq 0x5d3c(%rip), %rdx      # 0x9378
leaq (%rdx,%rdx,2), %rsi
movl %ecx, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
leaq 0x5d2f(%rip), %rcx      # 0x9380
movl %eax, %eax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
movsd %xmm0, (%rcx,%rsi,8)
subsd %xmm2, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm1, 0x8(%rcx,%rsi,8)
leal 0x1(%rdx), %eax
movl %eax, 0x5cfe(%rip)      # 0x9378
movsd %xmm0, 0x10(%rcx,%rsi,8)
movl 0x3005d11(%rip), %r10d  # 0x3009398
movl 0x5cef(%rip), %eax      # 0x937c
incl %eax
xorl %ecx, %ecx
testl %r10d, %r10d
cmovel %eax, %ecx
movl %ecx, 0x5cdf(%rip)      # 0x937c
movl 0x5aa5(%rip), %eax      # 0x9148
leal 0x1(%rax), %ecx
movl %ecx, 0x5a9c(%rip)      # 0x9148
cmpb $0x0, 0x5c25(%rip)      # 0x92d8
je 0x374a
testl %ebx, %ebx
sete %cl
orb %al, %cl
testb $0x1, %cl
jne 0x374a
leaq 0x3005ce0(%rip), %rax   # 0x30093b0
movq (%rax), %rdi
xorps %xmm0, %xmm0
cvtss2sd 0x5bba(%rip), %xmm0     # 0x9298
xorps %xmm1, %xmm1
cvtss2sd 0x5b0f(%rip), %xmm1     # 0x91f8
xorps %xmm2, %xmm2
cvtss2sd 0x5c00(%rip), %xmm2     # 0x92f4
movl 0x5a92(%rip), %edx      # 0x918c
movl 0x5a90(%rip), %ecx      # 0x9190
movl 0x5b25(%rip), %r8d      # 0x922c
movl 0x5b22(%rip), %r9d      # 0x9230
movl 0x5a83(%rip), %r11d     # 0x9198
movl 0x5a85(%rip), %ebx      # 0x91a0
movl 0x5b16(%rip), %r14d     # 0x9238
movl 0x5b17(%rip), %r15d     # 0x9240
subq $0x8, %rsp
leaq 0x21f3(%rip), %rsi      # 0x5927
movb $0x3, %al
pushq %r10
pushq %r15
pushq %r14
pushq %rbx
pushq %r11
callq 0x1150
addq $0x38, %rsp
jmp 0x374e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq