#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_FORCE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int open_device_file(char *dev_file, int i2c_addr) {
  ((void)0);
  int fd = open(dev_file, O_RDWR);
  if (fd < 0)
    return -1;
  if (i2c_addr >= 0) {
    if (ioctl(fd, I2C_SLAVE_FORCE, i2c_addr) < 0) {
      close(fd);
      return -1;
    }
  }
  return fd;
}


x86 assembly (clang, -O0):
<open_device_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    116a <open_device_file+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <open_device_file+0x81>
cmpl   $0x0,-0x14(%rbp)
jl     11ab <open_device_file+0x7b>
mov    -0x18(%rbp),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11a6 <open_device_file+0x76>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <open_device_file+0x81>
jmp    11ab <open_device_file+0x7b>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_device_file>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     1177 <open_device_file+0x47>
mov    %eax,%ebp
test   %ebx,%ebx
js     116b <open_device_file+0x3b>
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %ebx,%edx
call   1030 <ioctl@plt>
test   %rax,%rax
js     1170 <open_device_file+0x40>
mov    %ebp,%r14d
jmp    1177 <open_device_file+0x47>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@I2C_SLAVE_FORCE = global i32 0
define i32 @open_device_file(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %28
13: ; preds = %2
%14 = load i32, i32* %5
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i32, i32* %6
%18 = load i32, i32* @I2C_SLAVE_FORCE
%19 = load i32, i32* %5
%20 = call i64 @ioctl(i32 %17, i32 %18, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* %6
%24 = call i32 @close(i32 %23)
store i32 -1, i32* %3
br label %28
25: ; preds = %16
br label %26
26: ; preds = %25, %13
%27 = load i32, i32* %6
store i32 %27, i32* %3
br label %28
28: ; preds = %26, %22, %12
%29 = load i32, i32* %3
ret i32 %29
}

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