#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*/ I2C_FUNCS;
int /*<<< orphan*/ I2C_SLAVE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int init(char *device, int addr) {
  int file;
  unsigned long funcs;
  if ((file = open(device, O_RDWR)) < 0) {
    fprintf(stderr, "Error: Could not open file %s\n", device);
    return 0;
  }
  if (ioctl(file, I2C_FUNCS, &funcs) < 0) {
    fprintf(stderr,
            "Error: Could not get the adapter functionality matrix: %s\n",
            strerror(errno));
    close(file);
    return 0;
  }
  if (ioctl(file, I2C_SLAVE, addr) < 0) {
    fprintf(stderr, "Error: Cannot communicate with slave: %s\n",
            strerror(errno));
    close(file);
    return 0;
  }
  return file;
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11a2 <init+0x52>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1269 <init+0x119>
mov    -0x18(%rbp),%edi
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1203 <init+0xb3>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe35(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1269 <init+0x119>
mov    -0x18(%rbp),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1263 <init+0x113>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe10(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1269 <init+0x119>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11b0 <init+0x60>
mov    %eax,%ebp
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
test   %rax,%rax
js     11cc <init+0x7c>
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <ioctl@plt>
test   %rax,%rax
js     11ed <init+0x9d>
mov    %ebp,%ebx
jmp    121e <init+0xce>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
xor    %ebx,%ebx
jmp    121e <init+0xce>
mov    0x2dfd(%rip),%rax
mov    (%rax),%r14d
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe34(%rip),%rsi
jmp    120c <init+0xbc>
mov    0x2ddc(%rip),%rax
mov    (%rax),%r14d
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe4e(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Error: Could not open file %s\0A\00"
@I2C_FUNCS = global i32 0
@.str.1 = [59 x i8] c"Error: Could not get the adapter functionality matrix: %s\0A\00"
@errno = global i32 0
@I2C_SLAVE = global i32 0
@.str.2 = [42 x i8] c"Error: Cannot communicate with slave: %s\0A\00"
define i32 @init(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %4
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 0, i32* %3
br label %43
16: ; preds = %2
%17 = load i32, i32* %6
%18 = load i32, i32* @I2C_FUNCS
%19 = call i64 (i32, i32, ...) @ioctl(i32 %17, i32 %18, i64* %7)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
store i32 0, i32* %3
br label %43
28: ; preds = %16
%29 = load i32, i32* %6
%30 = load i32, i32* @I2C_SLAVE
%31 = load i32, i32* %5
%32 = call i64 (i32, i32, ...) @ioctl(i32 %29, i32 %30, i32 %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %6
%40 = call i32 @close(i32 %39)
store i32 0, i32* %3
br label %43
41: ; preds = %28
%42 = load i32, i32* %6
store i32 %42, i32* %3
br label %43
43: ; preds = %41, %34, %21, %12
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Error: Could not open file %s\0A\00"
@I2C_FUNCS = global i32 0
@.str.1 = [59 x i8] c"Error: Could not get the adapter functionality matrix: %s\0A\00"
@errno = global i32 0
@I2C_SLAVE = global i32 0
@.str.2 = [42 x i8] c"Error: Cannot communicate with slave: %s\0A\00"
define i32 @init(i8* %0, i32 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %31
11: ; preds = %2
%12 = load i32, i32* @I2C_FUNCS
%13 = call i64 (i32, i32, ...) @ioctl(i32 %6, i32 %12, i64* %3)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 @close(i32 %6)
br label %31
21: ; preds = %11
%22 = load i32, i32* @I2C_SLAVE
%23 = call i64 (i32, i32, ...) @ioctl(i32 %6, i32 %22, i32 %1)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i32 @close(i32 %6)
br label %31
31: ; preds = %21, %25, %15, %8
%32 = phi i32 [ 0, %8 ], [ 0, %15 ], [ 0, %25 ], [ %6, %21 ]
ret i32 %32
}