// File: /workspace/github_c_makefile_star2_O0/Openvario[P]sensord/humidity.c
// Function: sht4x_open
int sht4x_open (t_ds2482 *sensor, unsigned char i2c_address) {

	uint8_t data[6]={0x94,0x89,0,0,0,0};

	sensor->fd = open(I2C_DEVICE, O_RDWR);
	if (sensor->fd < 0) {
		fprintf(stderr, "Error opening file: %s\n", strerror(errno));
		return 1;
	}
	if (ioctl(sensor->fd, I2C_SLAVE, i2c_address) < 0) {
		fprintf(stderr, "ioctl error: %s\n", strerror(errno));
		return 1;
	}

	if (write(sensor->fd,data,1)!=1) return 2;                                    // Do SHT4x soft reset
	struct timespec nstime = {0,15e6};
	while (nanosleep (&nstime,&nstime)) ;                                           // Wait 15 microseconds after reset
	if (write(sensor->fd,data+2,1)!=1) return 2;                                    // Request Serial Number
	if (read(sensor->fd,data,6)!=6) {
		sensor->sensor_type=SHT4X;
		if (si7021_crc_check((data[0]<<8)|(data[1]),data[2])!=0) return 4;
		if (si7021_crc_check((data[3]<<8)|(data[4]),data[5])!=0) return 4;
		fprintf(stderr, "SHT4x, Serial Number: 0x%x%x%x%x - ",data[0],data[1],data[3],data[4]);
	} else {
		data[0]=0x30;
		data[1]=0xa2;
		data[2]=0x36;
		data[3]=0x82;
		if (write(sensor->fd,data,2)!=2) return 2;                                    // Do SHT4x soft reset
		nstime.tv_nsec=15e6;
		while (nanosleep (&nstime,&nstime)) ;                                           // Wait 15 microseconds after reset
		if (write(sensor->fd,data+2,2)!=2) return 2;                                    // Request Serial Number
		if (read(sensor->fd,data,6)!=6) {
			sensor->sensor_type=SHT85;
			if (si7021_crc_check((data[0]<<8)|(data[1]),data[2])!=0) return 5;
			if (si7021_crc_check((data[3]<<8)|(data[4]),data[5])!=0) return 5;
			fprintf(stderr, "SHT85, Serial Number: 0x%x%x%x%x - ",data[0],data[1],data[3],data[4]);
		} else return 3;
	}

	if (g_debug > 0) {
		if (sensor->sensor_type==SHT4X)
			fprintf(stderr, "Opened SHT4x\n");
		else
			fprintf(stderr, "Opened SHT85\n");
	}
	sensor->address = i2c_address;
	return (0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movl 0x4060(%rip), %eax      # 0xc9c8
movl %eax, -0x17(%rbp)
movw 0x405a(%rip), %ax       # 0xc9cc
movw %ax, -0x13(%rbp)
leaq 0x2a5f(%rip), %rdi      # 0xb3dc
movl $0x2, %esi
movb $0x0, %al
callq 0x2240
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jge 0x89d5
movq 0x6657(%rip), %rax      # 0xeff8
movq (%rax), %rax
movq %rax, -0x30(%rbp)
callq 0x2030
movl (%rax), %edi
callq 0x22d0
movq -0x30(%rbp), %rdi
movq %rax, %rdx
leaq 0x2a25(%rip), %rsi      # 0xb3e7
movb $0x0, %al
callq 0x21d0
movl $0x1, -0x4(%rbp)
jmp 0x8ccb
movq -0x10(%rbp), %rax
movl (%rax), %edi
movzbl -0x11(%rbp), %edx
movl $0x703, %esi            # imm = 0x703
movb $0x0, %al
callq 0x2140
cmpl $0x0, %eax
jge 0x8a2b
movq 0x6601(%rip), %rax      # 0xeff8
movq (%rax), %rax
movq %rax, -0x38(%rbp)
callq 0x2030
movl (%rax), %edi
callq 0x22d0
movq -0x38(%rbp), %rdi
movq %rax, %rdx
leaq 0x2634(%rip), %rsi      # 0xb04c
movb $0x0, %al
callq 0x21d0
movl $0x1, -0x4(%rbp)
jmp 0x8ccb
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x17(%rbp), %rsi
movl $0x1, %edx
callq 0x20a0
cmpq $0x1, %rax
je 0x8a51
movl $0x2, -0x4(%rbp)
jmp 0x8ccb
movq 0x4210(%rip), %rax      # 0xcc68
movq %rax, -0x28(%rbp)
movq 0x420d(%rip), %rax      # 0xcc70
movq %rax, -0x20(%rbp)
leaq -0x28(%rbp), %rsi
movq %rsi, %rdi
callq 0x2120
cmpl $0x0, %eax
je 0x8a7a
jmp 0x8a67
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x17(%rbp), %rsi
addq $0x2, %rsi
movl $0x1, %edx
callq 0x20a0
cmpq $0x1, %rax
je 0x8aa4
movl $0x2, -0x4(%rbp)
jmp 0x8ccb
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x17(%rbp), %rsi
movl $0x6, %edx
callq 0x2180
cmpq $0x6, %rax
je 0x8b47
movq -0x10(%rbp), %rax
movb $0x6, 0x30(%rax)
movzbl -0x17(%rbp), %edi
shll $0x8, %edi
movzbl -0x16(%rbp), %eax
orl %eax, %edi
movzbl -0x15(%rbp), %esi
callq 0x88b0
cmpl $0x0, %eax
je 0x8af1
movl $0x4, -0x4(%rbp)
jmp 0x8ccb
movzbl -0x14(%rbp), %edi
shll $0x8, %edi
movzbl -0x13(%rbp), %eax
orl %eax, %edi
movzbl -0x12(%rbp), %esi
callq 0x88b0
cmpl $0x0, %eax
je 0x8b18
movl $0x4, -0x4(%rbp)
jmp 0x8ccb
movq 0x64d9(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movzbl -0x17(%rbp), %edx
movzbl -0x16(%rbp), %ecx
movzbl -0x14(%rbp), %r8d
movzbl -0x13(%rbp), %r9d
leaq 0x3f19(%rip), %rsi      # 0xca54
movb $0x0, %al
callq 0x21d0
jmp 0x8c6d
movb $0x30, -0x17(%rbp)
movb $-0x5e, -0x16(%rbp)
movb $0x36, -0x15(%rbp)
movb $-0x7e, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x17(%rbp), %rsi
movl $0x2, %edx
callq 0x20a0
cmpq $0x2, %rax
je 0x8b7d
movl $0x2, -0x4(%rbp)
jmp 0x8ccb
movq $0xe4e1c0, -0x20(%rbp)  # imm = 0xE4E1C0
leaq -0x28(%rbp), %rsi
movq %rsi, %rdi
callq 0x2120
cmpl $0x0, %eax
je 0x8b98
jmp 0x8b85
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x17(%rbp), %rsi
addq $0x2, %rsi
movl $0x2, %edx
callq 0x20a0
cmpq $0x2, %rax
je 0x8bc2
movl $0x2, -0x4(%rbp)
jmp 0x8ccb
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x17(%rbp), %rsi
movl $0x6, %edx
callq 0x2180
cmpq $0x6, %rax
je 0x8c62
movq -0x10(%rbp), %rax
movb $0x7, 0x30(%rax)
movzbl -0x17(%rbp), %edi
shll $0x8, %edi
movzbl -0x16(%rbp), %eax
orl %eax, %edi
movzbl -0x15(%rbp), %esi
callq 0x88b0
cmpl $0x0, %eax
je 0x8c0f
movl $0x5, -0x4(%rbp)
jmp 0x8ccb
movzbl -0x14(%rbp), %edi
shll $0x8, %edi
movzbl -0x13(%rbp), %eax
orl %eax, %edi
movzbl -0x12(%rbp), %esi
callq 0x88b0
cmpl $0x0, %eax
je 0x8c36
movl $0x5, -0x4(%rbp)
jmp 0x8ccb
movq 0x63bb(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movzbl -0x17(%rbp), %edx
movzbl -0x16(%rbp), %ecx
movzbl -0x14(%rbp), %r8d
movzbl -0x13(%rbp), %r9d
leaq 0x3e1f(%rip), %rsi      # 0xca78
movb $0x0, %al
callq 0x21d0
jmp 0x8c6b
movl $0x3, -0x4(%rbp)
jmp 0x8ccb
jmp 0x8c6d
leaq 0x6800(%rip), %rax      # 0xf474
cmpl $0x0, (%rax)
jle 0x8cba
movq -0x10(%rbp), %rax
movsbl 0x30(%rax), %eax
cmpl $0x6, %eax
jne 0x8ca0
movq 0x636b(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x3e05(%rip), %rsi      # 0xca9c
movb $0x0, %al
callq 0x21d0
jmp 0x8cb8
movq 0x6351(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x3df9(%rip), %rsi      # 0xcaaa
movb $0x0, %al
callq 0x21d0
jmp 0x8cba
movb -0x11(%rbp), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x4(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)