#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ I2C_SLAVE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int i2c_smbus_read_byte_data(int, int);
scalar_t__ i2c_smbus_write_byte(int, int);
scalar_t__ i2c_smbus_write_byte_data(int, int, int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int fd;
  int value;
  fd = open("/dev/i2c-1", O_RDWR);
  if (fd < 0) {
    perror("/dev/i2c-1");
    exit(EXIT_FAILURE);
  }
  if (ioctl(fd, I2C_SLAVE, 0x4F) < 0) {
    perror("Slave unreachable");
    exit(EXIT_FAILURE);
  }
  value = i2c_smbus_read_byte_data(fd, 0xAC);
  if (value < 0) {
    perror("Read ACCESS_CONFIG");
    exit(EXIT_FAILURE);
  }
  value |= 0x01;
  if (i2c_smbus_write_byte_data(fd, 0xAC, value) < 0) {
    perror("Write ACCESS_CONFIG");
    exit(EXIT_FAILURE);
  }
  if (i2c_smbus_write_byte(fd, 0xEE) < 0) {
    perror("Write START_CONVERT");
    exit(EXIT_FAILURE);
  }
  do {
    value = i2c_smbus_read_byte_data(fd, 0xAC);
    if (value < 0) {
      perror("Read ACCESS_CONFIG");
      exit(EXIT_FAILURE);
    }
  } while ((value & 0x80) == 0);
  value = i2c_smbus_read_byte_data(fd, 0xAA);
  if (value < 0) {
    perror("Read TEMPERATURE");
    exit(EXIT_FAILURE);
  }
  if (value > 127)
    value -= 256;
  fprintf(stdout, "%d\n", value);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d2 <main+0x52>
lea    0xe41(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
mov    $0x4f,%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    120c <main+0x8c>
lea    0xe12(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0xac,%esi
call   1090 <i2c_smbus_read_byte_data@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1240 <main+0xc0>
lea    0xdf0(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    $0xac,%esi
call   1060 <i2c_smbus_write_byte_data@plt>
cmp    $0x0,%rax
jge    127d <main+0xfd>
lea    0xdc6(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0xee,%esi
call   1040 <i2c_smbus_write_byte@plt>
cmp    $0x0,%rax
jge    12ae <main+0x12e>
lea    0xda9(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    12b3 <main+0x133>
mov    -0x14(%rbp),%edi
mov    $0xac,%esi
call   1090 <i2c_smbus_read_byte_data@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12e7 <main+0x167>
lea    0xd49(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    12ec <main+0x16c>
mov    -0x18(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     12b3 <main+0x133>
mov    -0x14(%rbp),%edi
mov    $0xaa,%esi
call   1090 <i2c_smbus_read_byte_data@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1331 <main+0x1b1>
lea    0xd3a(%rip),%rdi
call   1080 <perror@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpl   $0x7f,-0x18(%rbp)
jle    1346 <main+0x1c6>
mov    -0x18(%rbp),%eax
sub    $0x100,%eax
mov    %eax,-0x18(%rbp)
mov    0x2c7b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xd10(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2c5b(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     127a <main+0xfa>
mov    %eax,%ebx
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x4f,%edx
call   1030 <ioctl@plt>
test   %rax,%rax
js     1283 <main+0x103>
mov    %ebx,%edi
mov    $0xac,%esi
call   1090 <i2c_smbus_read_byte_data@plt>
test   %eax,%eax
js     1260 <main+0xe0>
or     $0x1,%eax
mov    %ebx,%edi
mov    $0xac,%esi
mov    %eax,%edx
call   1060 <i2c_smbus_write_byte_data@plt>
test   %rax,%rax
js     128c <main+0x10c>
mov    %ebx,%edi
mov    $0xee,%esi
call   1040 <i2c_smbus_write_byte@plt>
test   %rax,%rax
js     1295 <main+0x115>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    $0xac,%esi
call   1090 <i2c_smbus_read_byte_data@plt>
test   %eax,%eax
js     1260 <main+0xe0>
test   $0x80,%al
je     1210 <main+0x90>
mov    %ebx,%edi
mov    $0xaa,%esi
call   1090 <i2c_smbus_read_byte_data@plt>
test   %eax,%eax
js     129e <main+0x11e>
lea    -0x100(%rax),%edx
cmp    $0x7f,%eax
cmovbe %eax,%edx
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
lea    0xdb6(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xd7f(%rip),%rdi
jmp    1267 <main+0xe7>
lea    0xd81(%rip),%rdi
jmp    1267 <main+0xe7>
lea    0xd9d(%rip),%rdi
jmp    1267 <main+0xe7>
lea    0xda8(%rip),%rdi
jmp    1267 <main+0xe7>
lea    0xdb3(%rip),%rdi
jmp    1267 <main+0xe7>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@EXIT_FAILURE = global i32 0
@I2C_SLAVE = global i32 0
@.str.1 = [18 x i8] c"Slave unreachable\00"
@.str.2 = [19 x i8] c"Read ACCESS_CONFIG\00"
@.str.3 = [20 x i8] c"Write ACCESS_CONFIG\00"
@.str.4 = [20 x i8] c"Write START_CONVERT\00"
@.str.5 = [17 x i8] c"Read TEMPERATURE\00"
@stdout = global i32 0
@.str.6 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i32, i32* %6
%18 = load i32, i32* @I2C_SLAVE
%19 = call i64 @ioctl(i32 %17, i32 %18, i32 79)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %16
%26 = load i32, i32* %6
%27 = call i32 @i2c_smbus_read_byte_data(i32 %26, i32 172)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %25
%35 = load i32, i32* %7
%36 = or i32 %35, 1
store i32 %36, i32* %7
%37 = load i32, i32* %6
%38 = load i32, i32* %7
%39 = call i64 @i2c_smbus_write_byte_data(i32 %37, i32 172, i32 %38)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %34
%42 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %34
%46 = load i32, i32* %6
%47 = call i64 @i2c_smbus_write_byte(i32 %46, i32 238)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %45
br label %54
54: ; preds = %64, %53
%55 = load i32, i32* %6
%56 = call i32 @i2c_smbus_read_byte_data(i32 %55, i32 172)
store i32 %56, i32* %7
%57 = load i32, i32* %7
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %54
%60 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %54
br label %64
64: ; preds = %63
%65 = load i32, i32* %7
%66 = and i32 %65, 128
%67 = icmp eq i32 %66, 0
br i1 %67, label %54, label %68
68: ; preds = %64
%69 = load i32, i32* %6
%70 = call i32 @i2c_smbus_read_byte_data(i32 %69, i32 170)
store i32 %70, i32* %7
%71 = load i32, i32* %7
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %77
73: ; preds = %68
%74 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
77: ; preds = %68
%78 = load i32, i32* %7
%79 = icmp sgt i32 %78, 127
br i1 %79, label %80, label %83
80: ; preds = %77
%81 = load i32, i32* %7
%82 = sub nsw i32 %81, 256
store i32 %82, i32* %7
br label %83
83: ; preds = %80, %77
%84 = load i32, i32* @stdout
%85 = load i32, i32* %7
%86 = call i32 @fprintf(i32 %84, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %85)
%87 = load i32, i32* @EXIT_SUCCESS
ret i32 %87
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@EXIT_FAILURE = global i32 0
@I2C_SLAVE = global i32 0
@.str.1 = [18 x i8] c"Slave unreachable\00"
@.str.2 = [19 x i8] c"Read ACCESS_CONFIG\00"
@.str.3 = [20 x i8] c"Write ACCESS_CONFIG\00"
@.str.4 = [20 x i8] c"Write START_CONVERT\00"
@.str.5 = [17 x i8] c"Read TEMPERATURE\00"
@stdout = global i32 0
@.str.6 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = load i32, i32* @I2C_SLAVE
%12 = tail call i64 @ioctl(i32 %4, i32 %11, i32 79)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %10
%19 = tail call i32 @i2c_smbus_read_byte_data(i32 %4, i32 172)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %18
%26 = or i32 %19, 1
%27 = tail call i64 @i2c_smbus_write_byte_data(i32 %4, i32 172, i32 %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = tail call i32 @exit(i32 %31)
unreachable
33: ; preds = %25
%34 = tail call i64 @i2c_smbus_write_byte(i32 %4, i32 238)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = tail call i32 @exit(i32 %38)
unreachable
40: ; preds = %33, %47
%41 = tail call i32 @i2c_smbus_read_byte_data(i32 %4, i32 172)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
%46 = tail call i32 @exit(i32 %45)
unreachable
47: ; preds = %40
%48 = and i32 %41, 128
%49 = icmp eq i32 %48, 0
br i1 %49, label %40, label %50
50: ; preds = %47
%51 = tail call i32 @i2c_smbus_read_byte_data(i32 %4, i32 170)
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %50
%54 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = tail call i32 @exit(i32 %55)
unreachable
57: ; preds = %50
%58 = icmp ugt i32 %51, 127
%59 = add nsw i32 %51, -256
%60 = select i1 %58, i32 %59, i32 %51
%61 = load i32, i32* @stdout
%62 = tail call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %60)
%63 = load i32, i32* @EXIT_SUCCESS
ret i32 %63
}