#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ dev_close(int);
int dev_open(int, int, int /*<<< orphan*/);
float ds1621_read_TH_raw(int, int *);
float ds1621_read_TL_raw(int, int *);
float ds1621_read_temp_raw(int, int *);
int /*<<< orphan*/ ds1621_set_TH(int, double);
int /*<<< orphan*/ ds1621_set_TL(int, double);
int /*<<< orphan*/ dump_conf_byte(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, float, ...);
float raw_reg_to_temp(float, int, int);
int read_CONF(int);
int read_counter(int);
int read_slope(int);
int /*<<< orphan*/ reset_THF(int);
int /*<<< orphan*/ reset_TLF(int);
int /*<<< orphan*/ set_ONE_SHOT(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ start_convert(int);
int /*<<< orphan*/ stop_convert(int);
int /*<<< orphan*/ write_CONF(int, int);
main() {
  int dev_fd;
  int rc;
  int reg;
  int sh_reg;
  int slope;
  int counter;
  float temp;
  if ((dev_fd = dev_open(1, 0x48, 0)) >= 0) {
    reg = read_CONF(dev_fd);
    perror("read: DS1621_REG_CONF");
    printf("REG_CONF: %0x\n", reg);
    dump_conf_byte(reg);
    if (reg & 0x01)
      write_CONF(dev_fd, reg & 0xfe);
    perror("write: DS1621_REG_CONF");
    start_convert(dev_fd);
    perror("read: DS1621_COM_START");
    sleep(3);
    stop_convert(dev_fd);
    perror("read: DS1621_COM_STOP");
    counter = read_counter(dev_fd);
    perror("read: DS1621_REG_TEMP_COUNTER");
    printf("Reg: %0x\n", counter);
    slope = read_slope(dev_fd);
    perror("read: DS1621_REG_TEMP_SLOPE");
    printf("Reg: %0x\n", slope);
    temp = ds1621_read_temp_raw(dev_fd, &sh_reg);
    temp = raw_reg_to_temp(temp, slope, counter);
    printf("TEMP: %f, raw 9 Bit = 0x%0x [=%d]\n", temp, sh_reg, sh_reg);
    temp = ds1621_read_TH_raw(dev_fd, &sh_reg);
    temp = raw_reg_to_temp(temp, slope, counter);
    printf("TEMP_OVER: %f, raw 9 Bit = 0x%0x [=%d]\n", temp, sh_reg, sh_reg);
    temp = ds1621_read_TL_raw(dev_fd, &sh_reg);
    temp = raw_reg_to_temp(temp, slope, counter);
    printf("TEMP_HYST: %f, raw 9 Bit = 0x%0x [=%d]\n", temp, sh_reg, sh_reg);
    ds1621_set_TH(dev_fd, 22.5);
    ds1621_set_TL(dev_fd, 11.5);
    reset_THF(dev_fd);
    reset_TLF(dev_fd);
    set_ONE_SHOT(dev_fd);
    dev_close(dev_fd);
  } else {
    rc = 1;
  }
  return (rc);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
mov    $0x48,%esi
xor    %edx,%edx
call   1110 <dev_open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jl     1462 <main+0x212>
mov    -0x8(%rbp),%edi
call   1070 <read_CONF@plt>
mov    %eax,-0x10(%rbp)
lea    0xd82(%rip),%rdi
call   1100 <perror@plt>
cvtsi2ssl -0x10(%rbp),%xmm0
lea    0xd87(%rip),%rdi
mov    $0x1,%al
call   10a0 <printf@plt>
mov    -0x10(%rbp),%edi
call   1030 <dump_conf_byte@plt>
mov    -0x10(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     12ce <main+0x7e>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
and    $0xfe,%esi
call   1130 <write_CONF@plt>
lea    0xd60(%rip),%rdi
call   1100 <perror@plt>
mov    -0x8(%rbp),%edi
call   1060 <start_convert@plt>
lea    0xd63(%rip),%rdi
call   1100 <perror@plt>
mov    $0x3,%edi
call   1140 <sleep@plt>
mov    -0x8(%rbp),%edi
call   1170 <stop_convert@plt>
lea    0xd5c(%rip),%rdi
call   1100 <perror@plt>
mov    -0x8(%rbp),%edi
call   10b0 <read_counter@plt>
mov    %eax,-0x1c(%rbp)
lea    0xd5b(%rip),%rdi
call   1100 <perror@plt>
cvtsi2ssl -0x1c(%rbp),%xmm0
lea    0xd68(%rip),%rdi
mov    $0x1,%al
call   10a0 <printf@plt>
mov    -0x8(%rbp),%edi
call   1120 <read_slope@plt>
mov    %eax,-0x18(%rbp)
lea    0xd59(%rip),%rdi
call   1100 <perror@plt>
cvtsi2ssl -0x18(%rbp),%xmm0
lea    0xd3e(%rip),%rdi
mov    $0x1,%al
call   10a0 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1090 <ds1621_read_temp_raw@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10d0 <raw_reg_to_temp@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xd25(%rip),%rdi
mov    $0x1,%al
call   10a0 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   10f0 <ds1621_read_TH_raw@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10d0 <raw_reg_to_temp@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xd09(%rip),%rdi
mov    $0x1,%al
call   10a0 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1050 <ds1621_read_TL_raw@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10d0 <raw_reg_to_temp@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xcf2(%rip),%rdi
mov    $0x1,%al
call   10a0 <printf@plt>
mov    -0x8(%rbp),%edi
movsd  0xbe0(%rip),%xmm0
call   1150 <ds1621_set_TH@plt>
mov    -0x8(%rbp),%edi
movsd  0xbc8(%rip),%xmm0
call   1160 <ds1621_set_TL@plt>
mov    -0x8(%rbp),%edi
call   1040 <reset_THF@plt>
mov    -0x8(%rbp),%edi
call   10c0 <reset_TLF@plt>
mov    -0x8(%rbp),%edi
call   1080 <set_ONE_SHOT@plt>
mov    -0x8(%rbp),%edi
call   10e0 <dev_close@plt>
jmp    1469 <main+0x219>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%edi
mov    $0x48,%esi
xor    %edx,%edx
call   1110 <dev_open@plt>
test   %eax,%eax
jns    127c <main+0x2c>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <read_CONF@plt>
mov    %eax,%ebp
lea    0xd82(%rip),%rdi
call   1100 <perror@plt>
cvtsi2ss %ebp,%xmm0
lea    0xd88(%rip),%rdi
mov    $0x1,%al
call   10a0 <printf@plt>
mov    %ebp,%edi
call   1030 <dump_conf_byte@plt>
test   $0x1,%bpl
je     12c1 <main+0x71>
and    $0xfe,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   1130 <write_CONF@plt>
lea    0xd6d(%rip),%rdi
call   1100 <perror@plt>
mov    %ebx,%edi
call   1060 <start_convert@plt>
lea    0xd71(%rip),%rdi
call   1100 <perror@plt>
mov    $0x3,%edi
call   1140 <sleep@plt>
mov    %ebx,%edi
call   1170 <stop_convert@plt>
lea    0xd6b(%rip),%rdi
call   1100 <perror@plt>
mov    %ebx,%edi
call   10b0 <read_counter@plt>
mov    %eax,%r14d
lea    0xd6b(%rip),%rdi
call   1100 <perror@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %r14d,%xmm0
lea    0xd75(%rip),%r15
mov    %r15,%rdi
mov    $0x1,%al
call   10a0 <printf@plt>
mov    %ebx,%edi
call   1120 <read_slope@plt>
mov    %eax,%ebp
lea    0xd65(%rip),%rdi
call   1100 <perror@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   10a0 <printf@plt>
lea    0x4(%rsp),%r15
mov    %ebx,%edi
mov    %r15,%rsi
call   1090 <ds1621_read_temp_raw@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   10d0 <raw_reg_to_temp@plt>
mov    0x4(%rsp),%edx
lea    0xd47(%rip),%rdi
mov    %edx,%esi
mov    $0x1,%al
call   10a0 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   10f0 <ds1621_read_TH_raw@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   10d0 <raw_reg_to_temp@plt>
mov    0x4(%rsp),%edx
lea    0xd42(%rip),%rdi
mov    %edx,%esi
mov    $0x1,%al
call   10a0 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1050 <ds1621_read_TL_raw@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   10d0 <raw_reg_to_temp@plt>
mov    0x4(%rsp),%edx
lea    0xd42(%rip),%rdi
mov    %edx,%esi
mov    $0x1,%al
call   10a0 <printf@plt>
movsd  0xc29(%rip),%xmm0
mov    %ebx,%edi
call   1150 <ds1621_set_TH@plt>
movsd  0xc22(%rip),%xmm0
mov    %ebx,%edi
call   1160 <ds1621_set_TL@plt>
mov    %ebx,%edi
call   1040 <reset_THF@plt>
mov    %ebx,%edi
call   10c0 <reset_TLF@plt>
mov    %ebx,%edi
call   1080 <set_ONE_SHOT@plt>
mov    %ebx,%edi
call   10e0 <dev_close@plt>
jmp    126c <main+0x1c>

LLVM IR (-O0):
@.str = [22 x i8] c"read: DS1621_REG_CONF\00"
@.str.1 = [15 x i8] c"REG_CONF: %0x\0A\00"
@.str.2 = [23 x i8] c"write: DS1621_REG_CONF\00"
@.str.3 = [23 x i8] c"read: DS1621_COM_START\00"
@.str.4 = [22 x i8] c"read: DS1621_COM_STOP\00"
@.str.5 = [30 x i8] c"read: DS1621_REG_TEMP_COUNTER\00"
@.str.6 = [10 x i8] c"Reg: %0x\0A\00"
@.str.7 = [28 x i8] c"read: DS1621_REG_TEMP_SLOPE\00"
@.str.8 = [35 x i8] c"TEMP: %f, raw 9 Bit = 0x%0x [=%d]\0A\00"
@.str.9 = [40 x i8] c"TEMP_OVER: %f, raw 9 Bit = 0x%0x [=%d]\0A\00"
@.str.10 = [40 x i8] c"TEMP_HYST: %f, raw 9 Bit = 0x%0x [=%d]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
store i32 0, i32* %1
%9 = call i32 @dev_open(i32 1, i32 72, i32 0)
store i32 %9, i32* %2
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %91
11: ; preds = %0
%12 = load i32, i32* %2
%13 = call i32 @read_CONF(i32 %12)
store i32 %13, i32* %4
%14 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %4
%16 = sitofp i32 %15 to float
%17 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), float %16)
%18 = load i32, i32* %4
%19 = call i32 @dump_conf_byte(i32 %18)
%20 = load i32, i32* %4
%21 = and i32 %20, 1
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %11
%24 = load i32, i32* %2
%25 = load i32, i32* %4
%26 = and i32 %25, 254
%27 = call i32 @write_CONF(i32 %24, i32 %26)
br label %28
28: ; preds = %23, %11
%29 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* %2
%31 = call i32 @start_convert(i32 %30)
%32 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @sleep(i32 3)
%34 = load i32, i32* %2
%35 = call i32 @stop_convert(i32 %34)
%36 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* %2
%38 = call i32 @read_counter(i32 %37)
store i32 %38, i32* %7
%39 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%40 = load i32, i32* %7
%41 = sitofp i32 %40 to float
%42 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), float %41)
%43 = load i32, i32* %2
%44 = call i32 @read_slope(i32 %43)
store i32 %44, i32* %6
%45 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%46 = load i32, i32* %6
%47 = sitofp i32 %46 to float
%48 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), float %47)
%49 = load i32, i32* %2
%50 = call float @ds1621_read_temp_raw(i32 %49, i32* %5)
store float %50, float* %8
%51 = load float, float* %8
%52 = load i32, i32* %6
%53 = load i32, i32* %7
%54 = call float @raw_reg_to_temp(float %51, i32 %52, i32 %53)
store float %54, float* %8
%55 = load float, float* %8
%56 = load i32, i32* %5
%57 = load i32, i32* %5
%58 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), float %55, i32 %56, i32 %57)
%59 = load i32, i32* %2
%60 = call float @ds1621_read_TH_raw(i32 %59, i32* %5)
store float %60, float* %8
%61 = load float, float* %8
%62 = load i32, i32* %6
%63 = load i32, i32* %7
%64 = call float @raw_reg_to_temp(float %61, i32 %62, i32 %63)
store float %64, float* %8
%65 = load float, float* %8
%66 = load i32, i32* %5
%67 = load i32, i32* %5
%68 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0), float %65, i32 %66, i32 %67)
%69 = load i32, i32* %2
%70 = call float @ds1621_read_TL_raw(i32 %69, i32* %5)
store float %70, float* %8
%71 = load float, float* %8
%72 = load i32, i32* %6
%73 = load i32, i32* %7
%74 = call float @raw_reg_to_temp(float %71, i32 %72, i32 %73)
store float %74, float* %8
%75 = load float, float* %8
%76 = load i32, i32* %5
%77 = load i32, i32* %5
%78 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.10, i64 0, i64 0), float %75, i32 %76, i32 %77)
%79 = load i32, i32* %2
%80 = call i32 @ds1621_set_TH(i32 %79, double 2.250000e+01)
%81 = load i32, i32* %2
%82 = call i32 @ds1621_set_TL(i32 %81, double 1.150000e+01)
%83 = load i32, i32* %2
%84 = call i32 @reset_THF(i32 %83)
%85 = load i32, i32* %2
%86 = call i32 @reset_TLF(i32 %85)
%87 = load i32, i32* %2
%88 = call i32 @set_ONE_SHOT(i32 %87)
%89 = load i32, i32* %2
%90 = call i32 @dev_close(i32 %89)
br label %92
91: ; preds = %0
store i32 1, i32* %3
br label %92
92: ; preds = %91, %28
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
@.str = [22 x i8] c"read: DS1621_REG_CONF\00"
@.str.1 = [15 x i8] c"REG_CONF: %0x\0A\00"
@.str.2 = [23 x i8] c"write: DS1621_REG_CONF\00"
@.str.3 = [23 x i8] c"read: DS1621_COM_START\00"
@.str.4 = [22 x i8] c"read: DS1621_COM_STOP\00"
@.str.5 = [30 x i8] c"read: DS1621_REG_TEMP_COUNTER\00"
@.str.6 = [10 x i8] c"Reg: %0x\0A\00"
@.str.7 = [28 x i8] c"read: DS1621_REG_TEMP_SLOPE\00"
@.str.8 = [35 x i8] c"TEMP: %f, raw 9 Bit = 0x%0x [=%d]\0A\00"
@.str.9 = [40 x i8] c"TEMP_OVER: %f, raw 9 Bit = 0x%0x [=%d]\0A\00"
@.str.10 = [40 x i8] c"TEMP_HYST: %f, raw 9 Bit = 0x%0x [=%d]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @dev_open(i32 1, i32 72, i32 0)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %49
5: ; preds = %0
%6 = tail call i32 @read_CONF(i32 %3)
%7 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%8 = sitofp i32 %6 to float
%9 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), float %8)
%10 = tail call i32 @dump_conf_byte(i32 %6)
%11 = and i32 %6, 1
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %5
%14 = and i32 %6, 254
%15 = tail call i32 @write_CONF(i32 %3, i32 %14)
br label %16
16: ; preds = %13, %5
%17 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @start_convert(i32 %3)
%19 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%20 = tail call i32 @sleep(i32 3)
%21 = tail call i32 @stop_convert(i32 %3)
%22 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%23 = tail call i32 @read_counter(i32 %3)
%24 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%25 = sitofp i32 %23 to float
%26 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), float %25)
%27 = tail call i32 @read_slope(i32 %3)
%28 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%29 = sitofp i32 %27 to float
%30 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), float %29)
%31 = call float @ds1621_read_temp_raw(i32 %3, i32* %1)
%32 = call float @raw_reg_to_temp(float %31, i32 %27, i32 %23)
%33 = load i32, i32* %1
%34 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), float %32, i32 %33, i32 %33)
%35 = call float @ds1621_read_TH_raw(i32 %3, i32* %1)
%36 = call float @raw_reg_to_temp(float %35, i32 %27, i32 %23)
%37 = load i32, i32* %1
%38 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0), float %36, i32 %37, i32 %37)
%39 = call float @ds1621_read_TL_raw(i32 %3, i32* %1)
%40 = call float @raw_reg_to_temp(float %39, i32 %27, i32 %23)
%41 = load i32, i32* %1
%42 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.10, i64 0, i64 0), float %40, i32 %41, i32 %41)
%43 = call i32 @ds1621_set_TH(i32 %3, double 2.250000e+01)
%44 = call i32 @ds1621_set_TL(i32 %3, double 1.150000e+01)
%45 = call i32 @reset_THF(i32 %3)
%46 = call i32 @reset_TLF(i32 %3)
%47 = call i32 @set_ONE_SHOT(i32 %3)
%48 = call i32 @dev_close(i32 %3)
br label %49
49: ; preds = %0, %16
ret i32 1
}