#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*/ O_RDWR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ioctl(int, int, 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, 0x0703, 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    0x2e63(%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    1208 <wiringPiI2CSetup+0xb8>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%edx
mov    $0x703,%esi
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1202 <wiringPiI2CSetup+0xb2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1208 <wiringPiI2CSetup+0xb8>
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     11b0 <wiringPiI2CSetup+0x60>
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     11a4 <wiringPiI2CSetup+0x54>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x703,%esi
mov    %ebx,%edx
call   1030 <ioctl@plt>
test   %rax,%rax
mov    $0xffffffff,%eax
cmovns %ebp,%eax
jmp    11a9 <wiringPiI2CSetup+0x59>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%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
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 %32
24: ; preds = %18
%25 = load i32, i32* %5
%26 = load i32, i32* %3
%27 = call i64 @ioctl(i32 %25, i32 1795, i32 %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 -1, i32* %2
br label %32
30: ; preds = %24
%31 = load i32, i32* %5
store i32 %31, i32* %2
br label %32
32: ; preds = %30, %29, %23
%33 = load i32, i32* %2
ret i32 %33
}

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
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 %18, label %14
14: ; preds = %8
%15 = tail call i64 @ioctl(i32 %12, i32 1795, i32 %0)
%16 = icmp slt i64 %15, 0
%17 = select i1 %16, i32 -1, i32 %12
br label %18
18: ; preds = %14, %8
%19 = phi i32 [ -1, %8 ], [ %17, %14 ]
ret i32 %19
}