// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl 0x2ceb(%rip), %eax      # 0xca50
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x9d80
cmpl $0x1, -0x14(%rbp)
je 0x9d80
movl $0x6, -0x4(%rbp)
jmp 0xa018
movq -0x10(%rbp), %rax
movsbl 0x30(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x6, %eax
ja 0xa011
movq -0x20(%rbp), %rax
leaq 0x2c08(%rip), %rcx      # 0xc9ac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x1, -0x14(%rbp)
jne 0x9db9
movb $0x4, -0x16(%rbp)
jmp 0x9dbd
movb $0x2, -0x16(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x18(%rbp), %rsi
addq $0x2, %rsi
movl $0x2, %edx
callq 0x20a0
cmpq $0x2, %rax
je 0x9de7
movl $0x2, -0x4(%rbp)
jmp 0xa018
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x18(%rbp), %rsi
movl $0x1, %edx
callq 0x2180
cmpq $0x1, %rax
je 0x9e0d
movl $0x3, -0x4(%rbp)
jmp 0xa018
movzbl -0x18(%rbp), %eax
andl $0x1, %eax
movl -0x14(%rbp), %ecx
andl $0x1, %ecx
cmpl %ecx, %eax
je 0x9e2a
movl $0x4, -0x4(%rbp)
jmp 0xa018
jmp 0xa011
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x18(%rbp), %rsi
movl $0x1, %edx
callq 0x20a0
cmpq $0x1, %rax
je 0x9e55
movl $0x2, -0x4(%rbp)
jmp 0xa018
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x18(%rbp), %rsi
addq $0x2, %rsi
movl $0x1, %edx
callq 0x2180
cmpq $0x1, %rax
je 0x9e7f
movl $0x2, -0x4(%rbp)
jmp 0xa018
cmpl $0x1, -0x14(%rbp)
jne 0x9e91
movzbl -0x16(%rbp), %eax
orl $0x4, %eax
movb %al, -0x16(%rbp)
jmp 0x9e9d
movzbl -0x16(%rbp), %eax
andl $0xfb, %eax
movb %al, -0x16(%rbp)
movb $-0x19, -0x15(%rbp)
movb -0x16(%rbp), %al
movb %al, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x18(%rbp), %rsi
addq $0x1, %rsi
movl $0x2, %edx
callq 0x20a0
cmpq $0x2, %rax
je 0x9ed1
movl $0x3, -0x4(%rbp)
jmp 0xa018
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x18(%rbp), %rsi
addq $0x3, %rsi
movl $0x1, %edx
callq 0x20a0
cmpq $0x1, %rax
je 0x9efb
movl $0x3, -0x4(%rbp)
jmp 0xa018
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x18(%rbp), %rsi
addq $0x2, %rsi
movl $0x1, %edx
callq 0x2180
cmpq $0x1, %rax
je 0x9f25
movl $0x3, -0x4(%rbp)
jmp 0xa018
movzbl -0x16(%rbp), %eax
movzbl -0x18(%rbp), %ecx
cmpl %ecx, %eax
je 0x9f3d
movl $0x4, -0x4(%rbp)
jmp 0xa018
jmp 0xa011
movb $0x39, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x18(%rbp), %rsi
movl $0x1, %edx
callq 0x20a0
cmpq $0x1, %rax
je 0x9f6c
movl $0x2, -0x4(%rbp)
jmp 0xa018
jmp 0xa011
movb $0x30, -0x18(%rbp)
movb $-0xe, -0x16(%rbp)
movb $0x3d, -0x15(%rbp)
cmpl $0x1, -0x14(%rbp)
jne 0x9f89
movb $0x6d, -0x17(%rbp)
jmp 0x9f8d
movb $0x66, -0x17(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x18(%rbp), %rsi
movl $0x4, %edx
callq 0x20a0
cmpq $0x4, %rax
je 0x9fb0
movl $0x2, -0x4(%rbp)
jmp 0xa018
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x18(%rbp), %rsi
movl $0x3, %edx
callq 0x2180
cmpq $0x3, %rax
je 0x9fd3
movl $0x3, -0x4(%rbp)
jmp 0xa018
movzbl -0x18(%rbp), %eax
sarl $0x5, %eax
andl $0x1, %eax
cmpl -0x14(%rbp), %eax
je 0x9feb
movl $0x4, -0x4(%rbp)
jmp 0xa018
movzbl -0x18(%rbp), %edi
shll $0x8, %edi
movzbl -0x17(%rbp), %eax
orl %eax, %edi
movzbl -0x16(%rbp), %esi
callq 0x88b0
cmpl $0x1, %eax
jne 0xa00f
movl $0x5, -0x4(%rbp)
jmp 0xa018
jmp 0xa011
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)