#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 O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int);
int /*<<< orphan*/ stderr;
int dev_init_device(char *dev_name) {
  char *device = dev_name;
  int fd = open(device, O_RDWR | O_NONBLOCK);
  if (fd < 0) {
    fprintf(stderr, "error: could not open device %s\n", device);
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<dev_init_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
mov    0x2e98(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1181 <dev_init_device+0x61>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe90(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1187 <dev_init_device+0x67>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dev_init_device>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ebd(%rip),%rax
mov    0x2eae(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1040 <open@plt>
test   %eax,%eax
js     1141 <dev_init_device+0x21>
pop    %rbx
ret
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"error: could not open device %s\0A\00"
define i32 @dev_init_device(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_NONBLOCK
%10 = or i32 %8, %9
%11 = call i32 @open(i8* %7, i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 -1, i32* %2
br label %20
18: ; preds = %1
%19 = load i32, i32* %5
store i32 %19, i32* %2
br label %20
20: ; preds = %18, %14
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"error: could not open device %s\0A\00"
define i32 @dev_init_device(i8* %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_NONBLOCK
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %1, %7
%11 = phi i32 [ -1, %7 ], [ %5, %1 ]
ret i32 %11
}