#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);
int ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int initI2cBus(char *bus, int address) {
  int i2cFileDesc = open(bus, O_RDWR);
  if (i2cFileDesc < 0) {
    printf("I2C: Unable to open bus for read/write (%s)\n", bus);
    perror("Error is:");
    exit(1);
  }
  int result = ioctl(i2cFileDesc, I2C_SLAVE, address);
  if (result < 0) {
    perror("I2C: Unable to set I2C device to slave address.");
    exit(1);
  }
  return i2cFileDesc;
}


x86 assembly (clang, -O0):
<initI2cBus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11a4 <initI2cBus+0x54>
mov    -0x8(%rbp),%rsi
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
lea    0xe98(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1040 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11db <initI2cBus+0x8b>
lea    0xe6b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initI2cBus>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     118c <initI2cBus+0x3c>
mov    %eax,%ebp
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14d,%edx
call   1040 <ioctl@plt>
test   %eax,%eax
js     11a4 <initI2cBus+0x54>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe6d(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
lea    0xe8b(%rip),%rdi
jmp    11ab <initI2cBus+0x5b>
lea    0xe8c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [45 x i8] c"I2C: Unable to open bus for read/write (%s)\0A\00"
@.str.1 = [10 x i8] c"Error is:\00"
@I2C_SLAVE = global i32 0
@.str.2 = [48 x i8] c"I2C: Unable to set I2C device to slave address.\00"
define i32 @initI2cBus(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* %5
%19 = load i32, i32* @I2C_SLAVE
%20 = load i32, i32* %4
%21 = call i32 @ioctl(i32 %18, i32 %19, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = call i32 @perror(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %17
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [45 x i8] c"I2C: Unable to open bus for read/write (%s)\0A\00"
@.str.1 = [10 x i8] c"Error is:\00"
@I2C_SLAVE = global i32 0
@.str.2 = [48 x i8] c"I2C: Unable to set I2C device to slave address.\00"
define i32 @initI2cBus(i8* %0, i32 %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = load i32, i32* @I2C_SLAVE
%12 = tail call i32 @ioctl(i32 %4, i32 %11, i32 %1)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10
ret i32 %4
}