// File: /workspace/github_c_makefile_star2_O1/Openvario[P]sensord/humidity.c
// Function: si7021_read_humidity
int si7021_read_humidity (t_ds2482 *sensor) {
	uint8_t data[6],x,y;
	double temp;

	sensor->humidity_valid=0;
	if (sensor->sensor_type!=HTU21D) sensor->temp_valid=0;
	switch (sensor->sensor_type) {
		case SI7021 : case HTU21D :
			if (read(sensor->fd, data, 3) != 3) return 4;
			if ((x=si7021_crc_check((data[0]<<8)|data[1],data[2]))==0) {
				temp = (double) ((data[0]<<8)|data[1]) * 125/65536.0 - 6;
				if (sensor->compensate) temp += (25-sensor->temperature) * -0.15;
				sensor->humidity = temp;
				sensor->humidity_valid = sensor->humidity_present;
			}
			if (sensor->sensor_type==HTU21D) return x;
			data[0]=0xe0;
			if (write(sensor->fd,data, 1) != 1) return 4;
			if (read(sensor->fd, data, 3) != 3) return 4;
			if ((y=si7021_crc_check((data[0]<<8)|data[1],data[2]))==0) {
				sensor->temperature = (double) ((data[0]<<8)|data[1]) * 175.72/65536.0 - 46.85;
				sensor->temp_valid = sensor->temp_present;
			}
			return ((y<<1)|x);
			break;
		case HTU31D :
			data[0]=0x0;
			if (write(sensor->fd,data, 1) != 1) return 4;
		case SHT4X : case SHT85 :
			if (read(sensor->fd, data, 6) != 6) return 4;
			x=si7021_crc_check((data[0]<<8)|data[1],data[2]);
			y=si7021_crc_check((data[3]<<8)|data[4],data[5]);
			switch (sensor->sensor_type) {
				case HTU31D :
					sensor->temperature = (double) ((data[0]<<8)|data[1]) * 165/65535.0 - 40;
					sensor->humidity = (double) ((data[3]<<8)|data[4]) * 100/65535.0;
					break;
				case SHT4X :
					sensor->temperature = (double) ((data[0]<<8)|data[1]) * 175/65535.0 - 45;
					sensor->humidity = (double) ((data[3]<<8)|data[4]) * 125/65535.0 - 6;
					break;
				case SHT85 :
					sensor->temperature = (double) ((data[0]<<8)|data[1]) * 175/65535.0 - 45;
 					sensor->humidity = (double) ((data[3]<<8)|data[4]) * 100/65535.0;
					break;
			}
			if (x==0) sensor->temp_valid = sensor->temp_present;
			if (y==0) sensor->humidity_valid = sensor->humidity_present;
			return ((x<<1)|y);
			break;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movb $0x0, 0x2f(%rdi)
movzbl 0x30(%rdi), %eax
cmpl $0x1, %eax
jne 0x868d
movl (%rbx), %edi
leaq 0xa(%rsp), %rsi
movl $0x3, %edx
callq 0x2180
movl $0x4, %ebp
cmpq $0x3, %rax
jne 0x8927
movzwl 0xa(%rsp), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movzbl 0xc(%rsp), %ecx
movl %eax, %edx
shll $0x8, %edx
movl $0x988000, %esi         # imm = 0x988000
movl $0x800000, %edi         # imm = 0x800000
movl $0xff8000, %r8d         # imm = 0xFF8000
testl %edx, %edi
je 0x861a
movl %esi, %r9d
andl %r8d, %r9d
xorl %r9d, %edx
shrl %edi
shrl %r8d
shrl %esi
cmpl $0x80, %edi
jne 0x860d
xorl %r14d, %r14d
cmpl %ecx, %edx
setne %cl
jne 0x867c
imull $0x7d, %eax, %eax
cvtsi2sd %eax, %xmm0
mulsd 0x229e(%rip), %xmm0     # 0xa8e0
addsd 0x22b6(%rip), %xmm0     # 0xa900
cmpl $0x0, 0x50(%rbx)
je 0x866d
movss 0x22c8(%rip), %xmm1     # 0xa920
subss 0x24(%rbx), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd 0x22a7(%rip), %xmm1     # 0xa910
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x28(%rbx)
movb 0x2d(%rbx), %al
movb %al, 0x2f(%rbx)
movb %cl, %r14b
cmpb $0x1, 0x30(%rbx)
jne 0x86b6
movl %r14d, %ebp
jmp 0x8927
movb $0x0, 0x2e(%rbx)
leal -0x6(%rax), %ecx
cmpl $0x2, %ecx
jb 0x8795
cmpl $0x2, %eax
je 0x8772
xorl %ebp, %ebp
cmpl $0x3, %eax
je 0x85c7
jmp 0x8927
leaq 0xa(%rsp), %rsi
movb $-0x20, (%rsi)
movl (%rbx), %edi
movl $0x1, %edx
callq 0x20b0
cmpq $0x1, %rax
jne 0x8927
movl (%rbx), %edi
leaq 0xa(%rsp), %rsi
movl $0x3, %edx
callq 0x2180
cmpq $0x3, %rax
jne 0x8927
movzwl 0xa(%rsp), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movzbl 0xc(%rsp), %ecx
movl %eax, %edx
shll $0x8, %edx
movl $0x988000, %esi         # imm = 0x988000
movl $0x800000, %edi         # imm = 0x800000
movl $0xff8000, %r8d         # imm = 0xFF8000
testl %edx, %edi
je 0x8722
movl %esi, %r9d
andl %r8d, %r9d
xorl %r9d, %edx
shrl %edi
shrl %r8d
shrl %esi
cmpl $0x80, %edi
jne 0x8715
movl $0x2, %ebp
cmpl %ecx, %edx
jne 0x876a
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x218f(%rip), %xmm0     # 0xa8d8
mulsd 0x218f(%rip), %xmm0     # 0xa8e0
addsd 0x218f(%rip), %xmm0     # 0xa8e8
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rbx)
movb 0x2c(%rbx), %al
movb %al, 0x2e(%rbx)
xorl %ebp, %ebp
orl %r14d, %ebp
jmp 0x8927
leaq 0xa(%rsp), %rsi
movb $0x0, (%rsi)
movl (%rbx), %edi
movl $0x1, %edx
callq 0x20b0
movl $0x4, %ebp
cmpq $0x1, %rax
jne 0x8927
movl (%rbx), %edi
leaq 0xa(%rsp), %rsi
movl $0x6, %edx
callq 0x2180
movl $0x4, %ebp
cmpq $0x6, %rax
jne 0x8927
movzwl 0xa(%rsp), %eax
rolw $0x8, %ax
movzwl %ax, %edi
movzbl 0xc(%rsp), %eax
movl %edi, %ecx
shll $0x8, %ecx
movl $0x988000, %edx         # imm = 0x988000
movl $0x800000, %esi         # imm = 0x800000
movl $0xff8000, %r8d         # imm = 0xFF8000
testl %ecx, %esi
je 0x87e8
movl %edx, %r9d
andl %r8d, %r9d
xorl %r9d, %ecx
shrl %esi
shrl %r8d
shrl %edx
cmpl $0x80, %esi
jne 0x87db
movzwl 0xd(%rsp), %edx
rolw $0x8, %dx
movzwl %dx, %r9d
movzbl 0xf(%rsp), %edx
movl %r9d, %esi
shll $0x8, %esi
movl $0x988000, %r8d         # imm = 0x988000
movl $0x800000, %r10d        # imm = 0x800000
movl $0xff8000, %r11d        # imm = 0xFF8000
testl %esi, %r10d
je 0x882e
movl %r8d, %ebp
andl %r11d, %ebp
xorl %ebp, %esi
shrl %r10d
shrl %r11d
shrl %r8d
cmpl $0x80, %r10d
jne 0x8821
xorl %r8d, %r8d
cmpl %edx, %esi
setne %r10b
movzbl 0x30(%rbx), %r11d
cmpl $0x7, %r11d
je 0x88c4
cmpl $0x6, %r11d
je 0x8884
cmpl $0x2, %r11d
jne 0x8903
imull $0xa5, %edi, %edi
cvtsi2sd %edi, %xmm0
movsd 0x207a(%rip), %xmm1     # 0xa8f0
divsd %xmm1, %xmm0
addsd 0x2086(%rip), %xmm0     # 0xa908
jmp 0x88e2
imull $0xaf, %edi, %edi
cvtsi2sd %edi, %xmm0
movsd 0x205a(%rip), %xmm1     # 0xa8f0
divsd %xmm1, %xmm0
addsd 0x2056(%rip), %xmm0     # 0xa8f8
cvtsd2ss %xmm0, %xmm2
imull $0x7d, %r9d, %edi
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
movss %xmm2, 0x24(%rbx)
divsd %xmm1, %xmm0
addsd 0x203e(%rip), %xmm0     # 0xa900
jmp 0x88fa
imull $0xaf, %edi, %edi
cvtsi2sd %edi, %xmm0
movsd 0x201a(%rip), %xmm1     # 0xa8f0
divsd %xmm1, %xmm0
addsd 0x2016(%rip), %xmm0     # 0xa8f8
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rbx)
imull $0x64, %r9d, %edi
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x28(%rbx)
cmpl %eax, %ecx
jne 0x890f
movb 0x2c(%rbx), %dil
movb %dil, 0x2e(%rbx)
movb %r10b, %r8b
cmpl %edx, %esi
jne 0x891c
movb 0x2d(%rbx), %dl
movb %dl, 0x2f(%rbx)
xorl %edx, %edx
cmpl %eax, %ecx
setne %dl
leal (%r8,%rdx,2), %ebp
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq