#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int piBoardRev();
int /*<<< orphan*/ stderr;
int wiringPiI2CSetup(int devId) {
  int rev, fd;
  char *device;
  if ((rev = piBoardRev()) < 0) {
    fprintf(stderr,
            "wiringPiI2CSetup: Unable to determine Pi board revision\n");
    exit(1);
  }
  if (rev == 1)
    device = "/dev/i2c-0";
  else
    device = "/dev/i2c-1";
  if ((fd = open(device, O_RDWR)) < 0)
    return -1;
  if (ioctl(fd, I2C_SLAVE, devId) < 0)
    return -1;
  return fd;
}


x86 assembly (clang, -O0):
<wiringPiI2CSetup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <piBoardRev@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    118d <wiringPiI2CSetup+0x3d>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x1,-0xc(%rbp)
jne    11a7 <wiringPiI2CSetup+0x57>
lea    0xe9b(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11b2 <wiringPiI2CSetup+0x62>
lea    0xe96(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    11dc <wiringPiI2CSetup+0x8c>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <wiringPiI2CSetup+0xbc>
mov    -0x10(%rbp),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1206 <wiringPiI2CSetup+0xb6>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <wiringPiI2CSetup+0xbc>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wiringPiI2CSetup>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <piBoardRev@plt>
test   %eax,%eax
js     11b4 <wiringPiI2CSetup+0x64>
cmp    $0x1,%eax
lea    0xecf(%rip),%rax
lea    0xed3(%rip),%rdi
cmove  %rax,%rdi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11a8 <wiringPiI2CSetup+0x58>
mov    %eax,%ebp
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %ebx,%edx
call   1030 <ioctl@plt>
test   %rax,%rax
mov    $0xffffffff,%eax
cmovns %ebp,%eax
jmp    11ad <wiringPiI2CSetup+0x5d>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [57 x i8] c"wiringPiI2CSetup: Unable to determine Pi board revision\0A\00"
@.str.1 = [11 x i8] c"/dev/i2c-0\00"
@.str.2 = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
define i32 @wiringPiI2CSetup(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
%7 = call i32 (...) @piBoardRev()
store i32 %7, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %13
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %18
17: ; preds = %13
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %6
br label %18
18: ; preds = %17, %16
%19 = load i8*, i8** %6
%20 = load i32, i32* @O_RDWR
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %5
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 -1, i32* %2
br label %33
24: ; preds = %18
%25 = load i32, i32* %5
%26 = load i32, i32* @I2C_SLAVE
%27 = load i32, i32* %3
%28 = call i64 @ioctl(i32 %25, i32 %26, i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 -1, i32* %2
br label %33
31: ; preds = %24
%32 = load i32, i32* %5
store i32 %32, i32* %2
br label %33
33: ; preds = %31, %30, %23
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [57 x i8] c"wiringPiI2CSetup: Unable to determine Pi board revision\0A\00"
@.str.1 = [11 x i8] c"/dev/i2c-0\00"
@.str.2 = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
define i32 @wiringPiI2CSetup(i32 %0) {
%2 = tail call i32 (...) @piBoardRev()
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = icmp eq i32 %2, 1
%10 = select i1 %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0)
%11 = load i32, i32* @O_RDWR
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %8
%15 = load i32, i32* @I2C_SLAVE
%16 = tail call i64 @ioctl(i32 %12, i32 %15, i32 %0)
%17 = icmp slt i64 %16, 0
%18 = select i1 %17, i32 -1, i32 %12
br label %19
19: ; preds = %14, %8
%20 = phi i32 [ -1, %8 ], [ %18, %14 ]
ret i32 %20
}