#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ I2C_SLAVE_FORCE;
int /*<<< orphan*/ O_RDWR;
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int i2c_open(char *device, uint8_t address) {
  int fd;
  int ret;
  fd = open(device, O_RDWR);
  if (fd < 0)
    return fd;
  ret = ioctl(fd, I2C_SLAVE_FORCE, address);
  if (ret < 0)
    return ret;
  return fd;
}


x86 assembly (clang, -O0):
<i2c_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2eae(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1159 <i2c_open+0x39>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118b <i2c_open+0x6b>
mov    -0x18(%rbp),%edi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
call   1030 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1185 <i2c_open+0x65>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118b <i2c_open+0x6b>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_open>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    0x2ebc(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1150 <i2c_open+0x30>
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %ebp,%edx
call   1030 <ioctl@plt>
test   %eax,%eax
cmovs  %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@I2C_SLAVE_FORCE = global i32 0
define i32 @i2c_open(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
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 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %6
store i32 %14, i32* %3
br label %26
15: ; preds = %2
%16 = load i32, i32* %6
%17 = load i32, i32* @I2C_SLAVE_FORCE
%18 = load i32, i32* %5
%19 = call i32 @ioctl(i32 %16, i32 %17, i32 %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = load i32, i32* %7
store i32 %23, i32* %3
br label %26
24: ; preds = %15
%25 = load i32, i32* %6
store i32 %25, i32* %3
br label %26
26: ; preds = %24, %22, %13
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@I2C_SLAVE_FORCE = global i32 0
define i32 @i2c_open(i8* nocapture %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 %11, label %6
6: ; preds = %2
%7 = load i32, i32* @I2C_SLAVE_FORCE
%8 = tail call i32 @ioctl(i32 %4, i32 %7, i32 %1)
%9 = icmp slt i32 %8, 0
%10 = select i1 %9, i32 %8, i32 %4
br label %11
11: ; preds = %6, %2
%12 = phi i32 [ %4, %2 ], [ %10, %6 ]
ret i32 %12
}