// File: /workspace/github_c_makefile_star2_O3/Openvario[P]sensord/humidity.c
// Function: si7021_configure_heater_onoff
int si7021_configure_heater_onoff (t_ds2482 *sensor, int value)
{
	uint8_t data[4] = {0xe7,0xe6,0x00,0x08};
	if ((value!=0) && (value!=1)) return 6;
	switch (sensor->sensor_type) {
		case HTU31D:
			if (value==1) data[2]=4; else data[2]=2;
			if (write(sensor->fd,data+2,2)!=2) return 2;
			if (read(sensor->fd,data,1)!=1) return 3;
			if ((data[0]&1)!=(value&1)) return 4;
			break;
		case HTU21D : case SI7021 :
			if (write(sensor->fd,data,1)!=1) return 2;		// Start read user register 1
			if (read(sensor->fd,data+2,1)!=1) return 2;		// Read user register 1
			if (value==1) data[2]|=4; else data[2]&=0xfb;		// Set heater value as desired
			data[3]=0xe7;
			data[0]=data[2];
			if (write(sensor->fd,data+1,2)!=2) return 3;		// Program it
			if (write(sensor->fd,data+3,1)!=1) return 3;		// Start readback
			if (read(sensor->fd,data+2,1)!=1) return 3;		// Readback
			if (data[2]!=data[0]) return 4;				// Verify Readback matches written value
			break;
		case SHT4X :
			data[0]=0x39;
			if (write(sensor->fd,data,1)!=1) return 2;
			break;
		case SHT85 :
			data[0]=0x30;
			data[2]=0xf2;
			data[3]=0x3d;
			if (value==1) data[1]=0x6d; else data[1]=0x66;
			if (write(sensor->fd,data,4)!=4) return 2;
			if (read(sensor->fd,data,3)!=3) return 3;
			if (((data[0]>>5)&1)!=value) return 4;
			if (si7021_crc_check((data[0]<<8)|data[1],data[2])==1) return 5;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl $0x800e6e7, 0x4(%rsp)   # imm = 0x800E6E7
movl $0x6, %ebp
cmpl $0x1, %esi
ja 0x8a64
movq %rdi, %r14
movzbl 0x30(%rdi), %eax
decl %eax
cmpl $0x6, %eax
ja 0x89d0
movl %esi, %ebx
leaq 0x20b7(%rip), %rcx      # 0xa92c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl (%r14), %edi
leaq 0x4(%rsp), %rsi
movl $0x1, %edx
callq 0x20b0
movl $0x2, %ebp
cmpq $0x1, %rax
jne 0x8a64
movl (%r14), %edi
leaq 0x6(%rsp), %r15
movl $0x1, %edx
movq %r15, %rsi
callq 0x2180
cmpq $0x1, %rax
jne 0x8a64
cmpl $0x1, %ebx
sete %al
leaq 0x5(%rsp), %rsi
movb 0x1(%rsi), %cl
andb $-0x5, %cl
shlb $0x2, %al
orb %cl, %al
movb %al, 0x1(%rsi)
movb $-0x19, 0x2(%rsi)
movb %al, -0x1(%rsi)
movl (%r14), %edi
movl $0x2, %edx
callq 0x20b0
movl $0x3, %ebp
cmpq $0x2, %rax
jne 0x8a64
leaq 0x7(%rsp), %rsi
movl (%r14), %edi
movl $0x1, %edx
callq 0x20b0
cmpq $0x1, %rax
jne 0x8a64
movl (%r14), %edi
movl $0x1, %edx
movq %r15, %rsi
callq 0x2180
cmpq $0x1, %rax
jne 0x8a64
movb 0x6(%rsp), %al
movl $0x4, %ebp
cmpb 0x4(%rsp), %al
je 0x89d0
jmp 0x8a64
cmpl $0x1, %ebx
sete %al
addb %al, %al
addb $0x2, %al
leaq 0x6(%rsp), %rsi
movb %al, (%rsi)
movl (%r14), %edi
movl $0x2, %edx
callq 0x20b0
movl $0x2, %ebp
cmpq $0x2, %rax
jne 0x8a64
movl (%r14), %edi
leaq 0x4(%rsp), %rsi
movl $0x1, %edx
callq 0x2180
movl $0x3, %ebp
cmpq $0x1, %rax
jne 0x8a64
movzbl 0x4(%rsp), %eax
andl $0x1, %eax
movl $0x4, %ebp
cmpl %ebx, %eax
je 0x89d0
jmp 0x8a64
leaq 0x4(%rsp), %rsi
movb $0x39, (%rsi)
movl (%r14), %edi
movl $0x1, %edx
callq 0x20b0
movl $0x2, %ebp
cmpq $0x1, %rax
jne 0x8a64
xorl %ebp, %ebp
jmp 0x8a64
leaq 0x4(%rsp), %rsi
movb $0x30, (%rsi)
movw $0x3df2, 0x2(%rsi)      # imm = 0x3DF2
cmpl $0x1, %ebx
movl $0x6d, %eax
movl $0x66, %ecx
cmovel %eax, %ecx
movb %cl, 0x1(%rsi)
movl (%r14), %edi
movl $0x4, %edx
callq 0x20b0
movl $0x2, %ebp
cmpq $0x4, %rax
jne 0x8a64
movl (%r14), %edi
leaq 0x4(%rsp), %rsi
movl $0x3, %edx
callq 0x2180
movl $0x3, %ebp
cmpq $0x3, %rax
jne 0x8a64
movzbl 0x4(%rsp), %eax
movl %eax, %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
movl $0x4, %ebp
cmpl %ebx, %ecx
jne 0x8a64
shll $0x8, %eax
movzbl 0x5(%rsp), %edi
orl %eax, %edi
movzbl 0x6(%rsp), %esi
callq 0x7a04
movl $0x5, %ebp
testl %eax, %eax
je 0x89d0
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq