#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*/ close(int);
int enable_lps331(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open_i2c_dev(int);
int /*<<< orphan*/ printf(char *, ...);
int read_pressure(int, double *);
int set_slave_addr(int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int who_am_i(int);
int main(int argc, char **argv) {
  int fd, res;
  double pressure;
  if ((fd = open_i2c_dev(1)) < 0) {
    fprintf(stderr, "open_i2c_dev() failed: %s\n", strerror(errno));
    return fd;
  }
  if ((res = set_slave_addr(fd, 0x5c)) < 0) {
    fprintf(stderr, "set_slave_addr() failed: %s\n", strerror(errno));
    close(fd);
    return res;
  }
  if ((res = who_am_i(fd)) < 0) {
    fprintf(stderr, "who_am_i() failed: %s\n", strerror(errno));
    close(fd);
    return res;
  }
  if (res == 0) {
    fprintf(stderr, "who_am_i() didn't return 0xbb\n");
    return -2;
  }
  if ((res = enable_lps331(fd)) < 0) {
    fprintf(stderr, "enable_lps331() failed: %s\n", strerror(errno));
    close(fd);
    return res;
  }
  if ((res = read_pressure(fd, &pressure)) < 0) {
    printf("Cannot get pressure\n");
  } else {
    printf("pressure = %g\n", pressure);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1090 <open_i2c_dev@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11f5 <main+0x65>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1373 <main+0x1e3>
mov    -0x14(%rbp),%edi
mov    $0x5c,%esi
call   1080 <set_slave_addr@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    124f <main+0xbf>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1373 <main+0x1e3>
mov    -0x14(%rbp),%edi
call   1030 <who_am_i@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    12a4 <main+0x114>
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1373 <main+0x1e3>
cmpl   $0x0,-0x18(%rbp)
jne    12d1 <main+0x141>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1373 <main+0x1e3>
mov    -0x14(%rbp),%edi
call   1060 <enable_lps331@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1326 <main+0x196>
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1373 <main+0x1e3>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10a0 <read_pressure@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1351 <main+0x1c1>
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1364 <main+0x1d4>
movsd  -0x20(%rbp),%xmm0
lea    0xd42(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%edi
call   10a0 <open_i2c_dev@plt>
mov    %eax,%ebx
test   %eax,%eax
js     121d <main+0x7d>
mov    %ebx,%edi
mov    $0x5c,%esi
call   1090 <set_slave_addr@plt>
test   %eax,%eax
js     124c <main+0xac>
mov    %ebx,%edi
call   1040 <who_am_i@plt>
test   %eax,%eax
js     126f <main+0xcf>
je     1292 <main+0xf2>
mov    %ebx,%edi
call   1070 <enable_lps331@plt>
test   %eax,%eax
js     12b0 <main+0x110>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   10b0 <read_pressure@plt>
test   %eax,%eax
js     12f2 <main+0x152>
movsd  0x8(%rsp),%xmm0
lea    0xe79(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    12fe <main+0x15e>
mov    0x2dbc(%rip),%rax
mov    (%rax),%ebp
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xdc5(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12e7 <main+0x147>
mov    %eax,%ebp
mov    0x2d8b(%rip),%rax
mov    (%rax),%r14d
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xdae(%rip),%rsi
jmp    12d1 <main+0x131>
mov    %eax,%ebp
mov    0x2d68(%rip),%rax
mov    (%rax),%r14d
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xda8(%rip),%rsi
jmp    12d1 <main+0x131>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xfffffffe,%ebx
jmp    12e7 <main+0x147>
mov    %eax,%ebp
mov    0x2d27(%rip),%rax
mov    (%rax),%r14d
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd9d(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xda0(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %ebx,%ebx
jmp    12e7 <main+0x147>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"open_i2c_dev() failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [29 x i8] c"set_slave_addr() failed: %s\0A\00"
@.str.2 = [23 x i8] c"who_am_i() failed: %s\0A\00"
@.str.3 = [31 x i8] c"who_am_i() didn't return 0xbb\0A\00"
@.str.4 = [28 x i8] c"enable_lps331() failed: %s\0A\00"
@.str.5 = [21 x i8] c"Cannot get pressure\0A\00"
@.str.6 = [15 x i8] c"pressure = %g\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @open_i2c_dev(i32 1)
store i32 %9, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* %6
store i32 %16, i32* %3
br label %71
17: ; preds = %2
%18 = load i32, i32* %6
%19 = call i32 @set_slave_addr(i32 %18, i32 92)
store i32 %19, i32* %7
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %7
store i32 %28, i32* %3
br label %71
29: ; preds = %17
%30 = load i32, i32* %6
%31 = call i32 @who_am_i(i32 %30)
store i32 %31, i32* %7
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
%40 = load i32, i32* %7
store i32 %40, i32* %3
br label %71
41: ; preds = %29
%42 = load i32, i32* %7
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
store i32 -2, i32* %3
br label %71
47: ; preds = %41
%48 = load i32, i32* %6
%49 = call i32 @enable_lps331(i32 %48)
store i32 %49, i32* %7
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %59
51: ; preds = %47
%52 = load i32, i32* @stderr
%53 = load i32, i32* @errno
%54 = call i8* @strerror(i32 %53)
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %54)
%56 = load i32, i32* %6
%57 = call i32 @close(i32 %56)
%58 = load i32, i32* %7
store i32 %58, i32* %3
br label %71
59: ; preds = %47
%60 = load i32, i32* %6
%61 = call i32 @read_pressure(i32 %60, double* %8)
store i32 %61, i32* %7
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %68
65: ; preds = %59
%66 = load double, double* %8
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), double %66)
br label %68
68: ; preds = %65, %63
%69 = load i32, i32* %6
%70 = call i32 @close(i32 %69)
store i32 0, i32* %3
br label %71
71: ; preds = %68, %51, %44, %33, %21, %11
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"open_i2c_dev() failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [29 x i8] c"set_slave_addr() failed: %s\0A\00"
@.str.2 = [23 x i8] c"who_am_i() failed: %s\0A\00"
@.str.3 = [31 x i8] c"who_am_i() didn't return 0xbb\0A\00"
@.str.4 = [28 x i8] c"enable_lps331() failed: %s\0A\00"
@.str.6 = [15 x i8] c"pressure = %g\0A\00"
@str = [20 x i8] c"Cannot get pressure\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
%5 = tail call i32 @open_i2c_dev(i32 1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %54
12: ; preds = %2
%13 = tail call i32 @set_slave_addr(i32 %5, i32 92)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = tail call i32 @close(i32 %5)
br label %54
21: ; preds = %12
%22 = tail call i32 @who_am_i(i32 %5)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = tail call i8* @strerror(i32 %26)
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = tail call i32 @close(i32 %5)
br label %54
30: ; preds = %21
%31 = icmp eq i32 %22, 0
br i1 %31, label %32, label %35
32: ; preds = %30
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %54
35: ; preds = %30
%36 = tail call i32 @enable_lps331(i32 %5)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = tail call i8* @strerror(i32 %40)
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%43 = tail call i32 @close(i32 %5)
br label %54
44: ; preds = %35
%45 = call i32 @read_pressure(i32 %5, double* %3)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %52
49: ; preds = %44
%50 = load double, double* %3
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), double %50)
br label %52
52: ; preds = %49, %47
%53 = call i32 @close(i32 %5)
br label %54
54: ; preds = %52, %38, %32, %24, %15, %7
%55 = phi i32 [ %5, %7 ], [ %13, %15 ], [ %22, %24 ], [ -2, %32 ], [ %36, %38 ], [ 0, %52 ]
ret i32 %55
}