// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movb $0x0, 0x2f(%rax)
movq -0x10(%rbp), %rax
movsbl 0x30(%rax), %eax
cmpl $0x1, %eax
je 0x97f9
movq -0x10(%rbp), %rax
movb $0x0, 0x2e(%rax)
movq -0x10(%rbp), %rax
movsbl 0x30(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0x6, %eax
ja 0x9c5d
movq -0x28(%rbp), %rax
leaq 0x3173(%rip), %rcx      # 0xc990
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x16(%rbp), %rsi
movl $0x3, %edx
callq 0x2180
cmpq $0x3, %rax
je 0x984c
movl $0x4, -0x4(%rbp)
jmp 0x9c64
movzbl -0x16(%rbp), %edi
shll $0x8, %edi
movzbl -0x15(%rbp), %eax
orl %eax, %edi
movzbl -0x14(%rbp), %esi
callq 0x88b0
movb %al, -0x17(%rbp)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x9904
movzbl -0x16(%rbp), %eax
shll $0x8, %eax
movzbl -0x15(%rbp), %ecx
orl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd 0x318e(%rip), %xmm1     # 0xca18
mulsd %xmm1, %xmm0
movsd 0x314a(%rip), %xmm1     # 0xc9e0
divsd %xmm1, %xmm0
movsd 0x316e(%rip), %xmm1     # 0xca10
subsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x98e4
movq -0x10(%rbp), %rax
movss 0x3187(%rip), %xmm0     # 0xca48
subss 0x24(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd -0x20(%rbp), %xmm1
movsd 0x3159(%rip), %xmm2     # 0xca30
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x28(%rax)
movq -0x10(%rbp), %rax
movb 0x2d(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x2f(%rax)
movq -0x10(%rbp), %rax
movsbl 0x30(%rax), %eax
cmpl $0x1, %eax
jne 0x991d
movzbl -0x17(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x9c64
movb $-0x20, -0x16(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x16(%rbp), %rsi
movl $0x1, %edx
callq 0x20a0
cmpq $0x1, %rax
je 0x9947
movl $0x4, -0x4(%rbp)
jmp 0x9c64
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x16(%rbp), %rsi
movl $0x3, %edx
callq 0x2180
cmpq $0x3, %rax
je 0x996d
movl $0x4, -0x4(%rbp)
jmp 0x9c64
movzbl -0x16(%rbp), %edi
shll $0x8, %edi
movzbl -0x15(%rbp), %eax
orl %eax, %edi
movzbl -0x14(%rbp), %esi
callq 0x88b0
movb %al, -0x18(%rbp)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x99de
movzbl -0x16(%rbp), %eax
shll $0x8, %eax
movzbl -0x15(%rbp), %ecx
orl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd 0x3041(%rip), %xmm1     # 0xc9e8
mulsd %xmm1, %xmm0
movsd 0x302d(%rip), %xmm1     # 0xc9e0
divsd %xmm1, %xmm0
movsd 0x3019(%rip), %xmm1     # 0xc9d8
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x24(%rax)
movq -0x10(%rbp), %rax
movb 0x2c(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x2e(%rax)
movzbl -0x18(%rbp), %eax
shll %eax
movzbl -0x17(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x9c64
movb $0x0, -0x16(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x16(%rbp), %rsi
movl $0x1, %edx
callq 0x20a0
cmpq $0x1, %rax
je 0x9a1c
movl $0x4, -0x4(%rbp)
jmp 0x9c64
jmp 0x9a1e
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x16(%rbp), %rsi
movl $0x6, %edx
callq 0x2180
cmpq $0x6, %rax
je 0x9a44
movl $0x4, -0x4(%rbp)
jmp 0x9c64
movw -0x16(%rbp), %ax
rolw $0x8, %ax
movzwl %ax, %edi
movzbl -0x14(%rbp), %esi
callq 0x88b0
movb %al, -0x17(%rbp)
movw -0x13(%rbp), %ax
rolw $0x8, %ax
movzwl %ax, %edi
movzbl -0x11(%rbp), %esi
callq 0x88b0
movb %al, -0x18(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x30(%rax), %eax
movl %eax, -0x2c(%rbp)
subl $0x2, %eax
je 0x9aa3
jmp 0x9a84
movl -0x2c(%rbp), %eax
subl $0x6, %eax
je 0x9b20
jmp 0x9a92
movl -0x2c(%rbp), %eax
subl $0x7, %eax
je 0x9ba6
jmp 0x9c1e
movzbl -0x16(%rbp), %eax
shll $0x8, %eax
movzbl -0x15(%rbp), %ecx
orl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd 0x2f6c(%rip), %xmm1     # 0xca28
mulsd %xmm1, %xmm0
movsd 0x2f28(%rip), %xmm1     # 0xc9f0
divsd %xmm1, %xmm0
movsd 0x2f4c(%rip), %xmm1     # 0xca20
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x24(%rax)
movzbl -0x13(%rbp), %eax
shll $0x8, %eax
movzbl -0x12(%rbp), %ecx
orl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd 0x2efa(%rip), %xmm1     # 0xc9f8
mulsd %xmm1, %xmm0
movsd 0x2ee6(%rip), %xmm1     # 0xc9f0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x28(%rax)
jmp 0x9c1e
movzbl -0x16(%rbp), %eax
shll $0x8, %eax
movzbl -0x15(%rbp), %ecx
orl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd 0x2ecf(%rip), %xmm1     # 0xca08
mulsd %xmm1, %xmm0
movsd 0x2eab(%rip), %xmm1     # 0xc9f0
divsd %xmm1, %xmm0
movsd 0x2eaf(%rip), %xmm1     # 0xca00
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x24(%rax)
movzbl -0x13(%rbp), %eax
shll $0x8, %eax
movzbl -0x12(%rbp), %ecx
orl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd 0x2e9d(%rip), %xmm1     # 0xca18
mulsd %xmm1, %xmm0
movsd 0x2e69(%rip), %xmm1     # 0xc9f0
divsd %xmm1, %xmm0
movsd 0x2e7d(%rip), %xmm1     # 0xca10
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x28(%rax)
jmp 0x9c1e
movzbl -0x16(%rbp), %eax
shll $0x8, %eax
movzbl -0x15(%rbp), %ecx
orl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd 0x2e49(%rip), %xmm1     # 0xca08
mulsd %xmm1, %xmm0
movsd 0x2e25(%rip), %xmm1     # 0xc9f0
divsd %xmm1, %xmm0
movsd 0x2e29(%rip), %xmm1     # 0xca00
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x24(%rax)
movzbl -0x13(%rbp), %eax
shll $0x8, %eax
movzbl -0x12(%rbp), %ecx
orl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd 0x2df7(%rip), %xmm1     # 0xc9f8
mulsd %xmm1, %xmm0
movsd 0x2de3(%rip), %xmm1     # 0xc9f0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x28(%rax)
movzbl -0x17(%rbp), %eax
cmpl $0x0, %eax
jne 0x9c35
movq -0x10(%rbp), %rax
movb 0x2c(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x2e(%rax)
movzbl -0x18(%rbp), %eax
cmpl $0x0, %eax
jne 0x9c4c
movq -0x10(%rbp), %rax
movb 0x2d(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x2f(%rax)
movzbl -0x17(%rbp), %eax
shll %eax
movzbl -0x18(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x9c64
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)