// File: /workspace/github_c_makefile_star2_O1/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 0x2300(%rip), %xmm0     # 0x53c8
callq 0x1a9d
ucomiss 0x22fc(%rip), %xmm0     # 0x53d0
jbe 0x30e7
movl $0x8, 0x30062ac(%rip)   # 0x300938c
addl $0x8, 0x30062b1(%rip)   # 0x3009398
testb $0x1, 0x605a(%rip)      # 0x9148
jne 0x3369
leaq 0x6115(%rip), %r15      # 0x9210
movq %r15, %rdi
callq 0x21b9
movl %eax, %r14d
movl 0x300628c(%rip), %esi   # 0x3009398
leaq 0x605d(%rip), %r13      # 0x9170
movq %r13, %rdi
callq 0x1fcf
movl %eax, %ebp
movq %r15, %rdi
callq 0x1f47
movl %eax, %r15d
callq 0x1a8c
movq %r13, %rdi
callq 0x1f88
movl %eax, %r12d
movl 0x60f6(%rip), %eax      # 0x9234
subl 0x60e8(%rip), %eax      # 0x922c
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0x1869f, %ecx          # imm = 0x1869F
ja 0x3632
cmpl $0x0, 0x300623a(%rip)   # 0x3009398
jne 0x318e
movl $0x0, 0x3006226(%rip)   # 0x3009390
movl $0x12c, %eax            # imm = 0x12C
addl 0x6023(%rip), %eax      # 0x9198
cmpl %eax, 0x6021(%rip)      # 0x919c
jbe 0x318e
movl $0x8, %eax
movl %eax, 0x3006204(%rip)   # 0x300938c
movl %eax, 0x300620a(%rip)   # 0x3009398
movl 0x30061f8(%rip), %eax   # 0x300938c
testl %eax, %eax
je 0x322d
xorl %ecx, %ecx
cmpl %eax, 0x30061f4(%rip)   # 0x3009398
setbe %cl
movl 0x2c(%r13,%rcx,4), %edx
subl 0x5fe6(%rip), %edx      # 0x9198
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
cmpl 0x30061d5(%rip), %ecx   # 0x3009394
jbe 0x31c7
movl %ecx, 0x30061cd(%rip)   # 0x3009394
decl %eax
movl %eax, 0x30061bd(%rip)   # 0x300938c
jne 0x322d
movl 0x30061bd(%rip), %eax   # 0x3009394
cmpl $0x10, %eax
jb 0x3223
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x60d5(%rip), %xmm0     # 0x92c0
callq 0x1110
mulsd 0x60d0(%rip), %xmm0     # 0x92c8
callq 0x1050
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
addsd 0x60c3(%rip), %xmm0     # 0x92d0
cvtsi2sdl 0x3006183(%rip), %xmm1 # 0x3009398
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, 0x3006175(%rip)   # 0x3009398
movl $0x0, 0x3006167(%rip)   # 0x3009394
movl 0x3006165(%rip), %eax   # 0x3009398
testl %eax, %eax
jle 0x35e1
movl $0x190, %ecx            # imm = 0x190
cmpl %ecx, %eax
cmovll %eax, %ecx
decl %ecx
movl %ecx, 0x300614b(%rip)   # 0x3009398
jne 0x3255
incl 0x300612f(%rip)         # 0x3009384
movl 0x3006135(%rip), %eax   # 0x3009390
incl %eax
movl %eax, 0x300612d(%rip)   # 0x3009390
cmpl $0x320, %eax            # imm = 0x320
jne 0x327e
xorl %eax, %eax
movl %eax, 0x300611e(%rip)   # 0x3009390
movl %eax, 0x3006120(%rip)   # 0x3009398
incl 0x300610a(%rip)         # 0x3009388
movl 0x5f14(%rip), %eax      # 0x9198
movl 0x5f16(%rip), %ecx      # 0x91a0
leal -0xf(%rcx), %edx
cmpl %edx, %eax
jbe 0x329b
movl $0x0, 0x30060fd(%rip)   # 0x3009398
leal 0x1f4(%rax), %edx
cmpl %edx, %ecx
jbe 0x3632
testl %ebx, %ebx
je 0x3632
cmpl $0x0, 0x30060e0(%rip)   # 0x3009398
je 0x3632
xorps %xmm0, %xmm0
cvtss2sd 0x5fcf(%rip), %xmm0     # 0x9298
mulsd 0x2137(%rip), %xmm0     # 0x5408
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd 0x5f8f(%rip), %xmm0     # 0x9270
mulsd 0x5f7f(%rip), %xmm1     # 0x9268
addsd %xmm0, %xmm1
addsd 0x5f83(%rip), %xmm1     # 0x9278
orl %r15d, %r14d
movl 0x5f32(%rip), %edx      # 0x9230
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
orl %r12d, %r14d
movl 0x5f1d(%rip), %edx      # 0x922c
cvtsi2sd %rdx, %xmm2
orl %r14d, %ebp
subsd %xmm2, %xmm0
divsd %xmm1, %xmm0
movslq 0x300605a(%rip), %rdx   # 0x3009380
leaq (%rdx,%rdx,2), %rsi
movl %ecx, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
leaq 0x1806045(%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, 0x300601c(%rip)   # 0x3009380
jmp 0x35d9
movl 0x3006029(%rip), %esi   # 0x3009398
leaq 0x5e9a(%rip), %r13      # 0x9210
movq %r13, %rdi
callq 0x1fcf
movl %eax, %r14d
leaq 0x5de8(%rip), %r12      # 0x9170
movq %r12, %rdi
callq 0x21b9
movl %eax, %ebp
movq %r13, %rdi
callq 0x1f88
movl %eax, %r15d
callq 0x1a8c
movq %r12, %rdi
callq 0x1f47
movl %eax, %r12d
movl 0x5de1(%rip), %eax      # 0x9194
subl 0x5dd3(%rip), %eax      # 0x918c
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0x1869f, %ecx          # imm = 0x1869F
ja 0x3632
cmpl $0x0, 0x3005fc5(%rip)   # 0x3009398
jne 0x3403
movl $0x0, 0x3005fb1(%rip)   # 0x3009390
movl $0x12c, %eax            # imm = 0x12C
addl 0x5e4e(%rip), %eax      # 0x9238
cmpl %eax, 0x5e4c(%rip)      # 0x923c
jbe 0x3403
movl $0x8, %eax
movl %eax, 0x3005f8f(%rip)   # 0x300938c
movl %eax, 0x3005f95(%rip)   # 0x3009398
movl 0x3005f83(%rip), %eax   # 0x300938c
testl %eax, %eax
je 0x34a2
xorl %ecx, %ecx
cmpl %eax, 0x3005f7f(%rip)   # 0x3009398
setbe %cl
movl 0x2c(%r13,%rcx,4), %edx
subl 0x5e11(%rip), %edx      # 0x9238
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
cmpl 0x3005f60(%rip), %ecx   # 0x3009394
jbe 0x343c
movl %ecx, 0x3005f58(%rip)   # 0x3009394
decl %eax
movl %eax, 0x3005f48(%rip)   # 0x300938c
jne 0x34a2
movl 0x3005f48(%rip), %eax   # 0x3009394
cmpl $0x10, %eax
jb 0x3498
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x5e60(%rip), %xmm0     # 0x92c0
callq 0x1110
mulsd 0x5e5b(%rip), %xmm0     # 0x92c8
callq 0x1050
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
addsd 0x5e4e(%rip), %xmm0     # 0x92d0
cvtsi2sdl 0x3005f0e(%rip), %xmm1 # 0x3009398
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, 0x3005f00(%rip)   # 0x3009398
movl $0x0, 0x3005ef2(%rip)   # 0x3009394
movl 0x3005ef0(%rip), %eax   # 0x3009398
testl %eax, %eax
jle 0x3608
movl $0x190, %ecx            # imm = 0x190
cmpl %ecx, %eax
cmovll %eax, %ecx
decl %ecx
movl %ecx, 0x3005ed6(%rip)   # 0x3009398
jne 0x34ca
incl 0x3005eba(%rip)         # 0x3009384
movl 0x3005ec0(%rip), %eax   # 0x3009390
incl %eax
movl %eax, 0x3005eb8(%rip)   # 0x3009390
cmpl $0x320, %eax            # imm = 0x320
jne 0x34f3
xorl %eax, %eax
movl %eax, 0x3005ea9(%rip)   # 0x3009390
movl %eax, 0x3005eab(%rip)   # 0x3009398
incl 0x3005e95(%rip)         # 0x3009388
movl 0x5d3f(%rip), %eax      # 0x9238
movl 0x5d41(%rip), %ecx      # 0x9240
leal -0xf(%rcx), %edx
cmpl %edx, %eax
jbe 0x3510
movl $0x0, 0x3005e88(%rip)   # 0x3009398
leal 0x1f4(%rax), %edx
cmpl %edx, %ecx
jbe 0x3632
testl %ebx, %ebx
je 0x3632
cmpl $0x0, 0x3005e6b(%rip)   # 0x3009398
je 0x3632
xorps %xmm0, %xmm0
cvtss2sd 0x5cba(%rip), %xmm0     # 0x91f8
mulsd 0x1ec2(%rip), %xmm0     # 0x5408
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd 0x5c7a(%rip), %xmm0     # 0x91d0
mulsd 0x5c6a(%rip), %xmm1     # 0x91c8
addsd %xmm0, %xmm1
addsd 0x5c6e(%rip), %xmm1     # 0x91d8
orl %r15d, %ebp
movl 0x5c1d(%rip), %edx      # 0x9190
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
orl %r12d, %ebp
movl 0x5c08(%rip), %edx      # 0x918c
cvtsi2sd %rdx, %xmm2
orl %r14d, %ebp
subsd %xmm2, %xmm0
divsd %xmm1, %xmm0
movslq 0x5ddd(%rip), %rdx      # 0x9378
leaq (%rdx,%rdx,2), %rsi
movl %ecx, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
leaq 0x5dd0(%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, 0x5d9f(%rip)      # 0x9378
movsd %xmm0, 0x10(%rcx,%rsi,8)
jmp 0x3632
leaq 0x5c28(%rip), %rdi      # 0x9210
movl 0x5c42(%rip), %eax      # 0x9230
leal (,%rax,8), %ecx
subl %eax, %ecx
addl 0x5c2f(%rip), %ecx      # 0x922c
shrl $0x3, %ecx
movl %ecx, 0x5c2a(%rip)      # 0x9230
jmp 0x362d
leaq 0x5b61(%rip), %rdi      # 0x9170
movl 0x5b7b(%rip), %eax      # 0x9190
leal (,%rax,8), %ecx
subl %eax, %ecx
addl 0x5b68(%rip), %ecx      # 0x918c
shrl $0x3, %ecx
movl %ecx, 0x5b63(%rip)      # 0x9190
callq 0x2234
movl 0x3005d5f(%rip), %r10d  # 0x3009398
movl 0x5d3d(%rip), %eax      # 0x937c
incl %eax
xorl %ecx, %ecx
testl %r10d, %r10d
cmovel %eax, %ecx
movl %ecx, 0x5d2d(%rip)      # 0x937c
movl 0x5af3(%rip), %eax      # 0x9148
leal 0x1(%rax), %ecx
movl %ecx, 0x5aea(%rip)      # 0x9148
cmpb $0x0, 0x5c73(%rip)      # 0x92d8
je 0x36fc
testl %ebx, %ebx
sete %cl
orb %al, %cl
testb $0x1, %cl
jne 0x36fc
leaq 0x3005d2e(%rip), %rax   # 0x30093b0
movq (%rax), %rdi
xorps %xmm0, %xmm0
cvtss2sd 0x5c08(%rip), %xmm0     # 0x9298
xorps %xmm1, %xmm1
cvtss2sd 0x5b5d(%rip), %xmm1     # 0x91f8
xorps %xmm2, %xmm2
cvtss2sd 0x5c4e(%rip), %xmm2     # 0x92f4
movl 0x5ae0(%rip), %edx      # 0x918c
movl 0x5ade(%rip), %ecx      # 0x9190
movl 0x5b73(%rip), %r8d      # 0x922c
movl 0x5b70(%rip), %r9d      # 0x9230
movl 0x5ad1(%rip), %r11d     # 0x9198
movl 0x5ad3(%rip), %ebx      # 0x91a0
movl 0x5b64(%rip), %r14d     # 0x9238
movl 0x5b65(%rip), %r15d     # 0x9240
subq $0x8, %rsp
leaq 0x2221(%rip), %rsi      # 0x5907
movb $0x3, %al
pushq %r10
pushq %r15
pushq %r14
pushq %rbx
pushq %r11
callq 0x1150
addq $0x38, %rsp
jmp 0x3700
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq