#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_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int open_device(unsigned char mode) {
  int fd = -1;
  if (mode & 0x0002) {
    fd = open("/dev/pcf8574", O_RDONLY);
    if (fd == -1)
      goto error;
    return fd;
  }
  if (mode & 0x0001) {
    fd = open("/dev/pcf8574", O_WRONLY);
    if (fd == -1)
      goto error;
    return fd;
  }
error:
  fprintf(stderr, "could not open %s\n", "/dev/pcf8574");
  return -1;
}


x86 assembly (clang, -O0):
<open_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movzbl -0x5(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1177 <open_device+0x57>
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    116c <open_device+0x4c>
jmp    11be <open_device+0x9e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e1 <open_device+0xc1>
movzbl -0x5(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11b9 <open_device+0x99>
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
lea    0xe69(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11ae <open_device+0x8e>
jmp    11be <open_device+0x9e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e1 <open_device+0xc1>
jmp    11be <open_device+0x9e>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
lea    0xe2b(%rip),%rdx
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_device>:
push   %rax
test   $0x2,%dil
jne    1136 <open_device+0x16>
test   $0x1,%dil
je     1152 <open_device+0x32>
mov    0x2e94(%rip),%rax
jmp    113d <open_device+0x1d>
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
lea    0xeba(%rip),%rdi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     1152 <open_device+0x32>
pop    %rcx
ret
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
lea    0xe97(%rip),%rdx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/pcf8574\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"could not open %s\0A\00"
define i32 @open_device(i8 zeroext %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
store i8 %0, i8* %3
store i32 -1, i32* %4
%5 = load i8, i8* %3
%6 = zext i8 %5 to i32
%7 = and i32 %6, 2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %9
br label %31
15: ; preds = %9
%16 = load i32, i32* %4
store i32 %16, i32* %2
br label %34
17: ; preds = %1
%18 = load i8, i8* %3
%19 = zext i8 %18 to i32
%20 = and i32 %19, 1
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %17
%23 = load i32, i32* @O_WRONLY
%24 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %23)
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %22
br label %31
28: ; preds = %22
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %34
30: ; preds = %17
br label %31
31: ; preds = %30, %27, %14
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %34
34: ; preds = %31, %28, %15
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/pcf8574\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"could not open %s\0A\00"
define i32 @open_device(i8 zeroext %0) {
%2 = zext i8 %0 to i32
%3 = and i32 %2, 2
%4 = icmp eq i32 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %16, label %19
9: ; preds = %1
%10 = and i32 %2, 1
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = load i32, i32* @O_WRONLY
%14 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %9, %12, %5
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %12, %5, %16
%20 = phi i32 [ -1, %16 ], [ %7, %5 ], [ %14, %12 ]
ret i32 %20
}