// File: /workspace/github_c_makefile_star2_O2/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
cmpl $0x1, %esi
jbe 0x7a3d
pushq $0x6
popq %r14
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %rbx
movzbl 0x30(%rdi), %eax
decl %eax
cmpl $0x6, %eax
ja 0x7b71
movl %esi, %ebp
leaq 0x1ed4(%rip), %rcx      # 0x992c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl (%rbx), %edi
leaq 0x4(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x20b0
pushq $0x2
popq %r14
cmpq $0x1, %rax
jne 0x7a2f
movl (%rbx), %edi
leaq 0x6(%rsp), %r15
pushq $0x1
popq %rdx
movq %r15, %rsi
callq 0x2180
cmpq $0x1, %rax
jne 0x7a2f
cmpl $0x1, %ebp
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 (%rbx), %edi
pushq $0x2
popq %rdx
callq 0x20b0
pushq $0x3
popq %r14
cmpq $0x2, %rax
jne 0x7a2f
leaq 0x7(%rsp), %rsi
movl (%rbx), %edi
pushq $0x1
popq %rdx
callq 0x20b0
cmpq $0x1, %rax
jne 0x7a2f
movl (%rbx), %edi
pushq $0x1
popq %rdx
movq %r15, %rsi
callq 0x2180
cmpq $0x1, %rax
jne 0x7a2f
movb 0x6(%rsp), %al
cmpb 0x4(%rsp), %al
jne 0x7bf9
jmp 0x7b71
cmpl $0x1, %ebp
sete %al
addb %al, %al
addb $0x2, %al
leaq 0x6(%rsp), %rsi
movb %al, (%rsi)
movl (%rbx), %edi
pushq $0x2
popq %rdx
callq 0x20b0
cmpq $0x2, %rax
jne 0x7beb
movl (%rbx), %edi
leaq 0x4(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2180
cmpq $0x1, %rax
jne 0x7bf2
movzbl 0x4(%rsp), %eax
andl $0x1, %eax
cmpl %ebp, %eax
je 0x7b71
jmp 0x7bf9
leaq 0x4(%rsp), %rsi
movb $0x39, (%rsi)
movl (%rbx), %edi
pushq $0x1
popq %rdx
callq 0x20b0
cmpq $0x1, %rax
jne 0x7beb
xorl %r14d, %r14d
jmp 0x7a2f
leaq 0x4(%rsp), %rsi
movb $0x30, (%rsi)
movw $0x3df2, 0x2(%rsi)      # imm = 0x3DF2
cmpl $0x1, %ebp
pushq $0x6d
popq %rax
pushq $0x66
popq %rcx
cmovel %eax, %ecx
movb %cl, 0x1(%rsi)
movl (%rbx), %edi
pushq $0x4
popq %rdx
callq 0x20b0
cmpq $0x4, %rax
jne 0x7beb
movl (%rbx), %edi
leaq 0x4(%rsp), %rsi
pushq $0x3
popq %rdx
callq 0x2180
cmpq $0x3, %rax
jne 0x7bf2
movzbl 0x4(%rsp), %eax
movl %eax, %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
cmpl %ebp, %ecx
jne 0x7bf9
shll $0x8, %eax
movzbl 0x5(%rsp), %edi
orl %eax, %edi
movzbl 0x6(%rsp), %esi
callq 0x6c90
testl %eax, %eax
je 0x7b71
pushq $0x5
jmp 0x7a2d
pushq $0x2
jmp 0x7a2d
pushq $0x3
jmp 0x7a2d
pushq $0x4
jmp 0x7a2d