#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_SLAVE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ exit(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int Init(int _adapter, int _devId) {
  int file;
  int adapter_nr = _adapter;
  char filename[20];
  snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
  file = open(filename, O_RDWR);
  if (file < 0) {
    printf("unable to open I2C adapter");
    exit(1);
  }
  int addr = _devId;
  if (ioctl(file, I2C_SLAVE, addr) < 0) {
    printf("unable to connect to device");
    exit(1);
  }
  return file;
}


x86 assembly (clang, -O0):
<Init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%ecx
mov    $0x13,%esi
lea    0xe89(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11b1 <Init+0x61>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
mov    -0x34(%rbp),%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    11eb <Init+0x9b>
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Init>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %edi,%ecx
lea    0xe9f(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x13,%esi
call   1040 <snprintf@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11a8 <Init+0x58>
mov    %eax,%ebp
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %ebx,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
js     11b1 <Init+0x61>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe5d(%rip),%rdi
jmp    11b8 <Init+0x68>
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/i2c-%d\00"
@O_RDWR = global i32 0
@.str.1 = [27 x i8] c"unable to open I2C adapter\00"
@I2C_SLAVE = global i32 0
@.str.2 = [28 x i8] c"unable to connect to device\00"
define i32 @Init(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [20 x i8]
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* %3
store i32 %9, i32* %6
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%11 = load i32, i32* %6
%12 = call i32 @snprintf(i8* %10, i32 19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* %13, i32 %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i32, i32* %4
store i32 %22, i32* %8
%23 = load i32, i32* %5
%24 = load i32, i32* @I2C_SLAVE
%25 = load i32, i32* %8
%26 = call i64 @ioctl(i32 %23, i32 %24, i32 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/i2c-%d\00"
@O_RDWR = global i32 0
@.str.1 = [27 x i8] c"unable to open I2C adapter\00"
@I2C_SLAVE = global i32 0
@.str.2 = [28 x i8] c"unable to connect to device\00"
define i32 @Init(i32 %0, i32 %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* %4, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = load i32, i32* @I2C_SLAVE
%14 = call i64 @ioctl(i32 %7, i32 %13, i32 %1)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %12
ret i32 %7
}